// module code

if (typeof(streamwork) == "undefined") {
    streamwork = {};
}
streamwork.methodGadget = {};
(function () {
    var $ = jQuery;
    var modules = {};

    function makeModule(name) {
        return {name:name};
    }

    streamwork.module = function (name) {
        var module = modules[name];
        if (module == null) {
            module = makeModule(name);
            modules[name] = module;
        }
        return module;
    };

    streamwork.getViewerId = function(){
        return streamwork.viewerId;
    };

    if (typeof(CSTAR) == "undefined"){
        CSTAR = {}
    };
    if (CSTAR.t == null){
        CSTAR.t = function(str){
                        return "["+str+"]";
                    };
    }

    //TODO: implement data methods using appdata for @shared user.
    var dataMethods = {
        set_data: function(data, callback){
            alert("set_data:" + JSON.stringify(data, null, 2));
            callback(data);
        },
        insert_array_item: function(data,callback){
            alert("insert_array_item:" + JSON.stringify(data, null, 2));
            callback(data);
        }
    };

    function asFunc(funcOrStr){
        if (typeof(funcOrStr) == "function"){
            return funcOrStr;
        } else {
            return eval("("+funcOrStr+")");
        }
    }

    // TODO: retrieve data based on resource and call
    $.ajax = function(opts){
        alert("ajax:" + JSON.stringify(opts, null, 2));
        if (opts.dataType == "jsonp"){
            // TODO: works only for retrieving
            var resource = opts.url.substring(opts.url.lastIndexOf(".")+2, opts.url.lastIndexOf("_callback="));
            var callback = asFunc(opts.jsonp);
            alert(resource);
            var data = [{id:1,text:"ABC"},{id:2, text:"XYZ"}];
            callback(data);

        }
    };


    $(document.body).ready(function () {
        osapi.newBatch().add("owner", osapi.people.getOwner())
             .add("viewer", osapi.people.getViewer()).execute(function(obj){

                streamwork.viewerId = obj.viewer.id;
                $(document.body).append("<div id='method-gadget'></div>");
                        for (var name in modules) {
                            if (modules.hasOwnProperty(name)){
                                var module = modules[name];
                                //TODO: retrieve initial data from @shared user
                                var controller = module.methodClient("method-gadget", streamwork.methodGadget.initialData || {}, {itemCreatorUuid: obj.owner.id});
                                controller.clientChannel = {
                                    publish: function(msg){
                                        var func = dataMethods[msg.type];
                                        if (func){
                                            func(msg.data,controller[msg.data.return_msg]);
                                        } else {
                                            alert("Unsupported data method: "+msg.type);
                                        }
                                    }
                                }
                            }
                        }
            });
    });
})();

// gadget code

streamwork.methodGadget.initialData = {			"impact_levels":[
				{"value":"1", "text":"Insignificant", "id":"impact_level_01"},
				{"value":"2", "text":"Minor", "id":"impact_level_02"},
				{"value":"3", "text":"Moderate", "id":"impact_level_03"},
				{"value":"4", "text":"Major", "id":"impact_level_04"},
				{"value":"5", "text":"Catastrophic", "id":"impact_level_05"}],
			"probability_levels":[
				{"value":"1", "text":"Rare", "id":"probability_level_01"},
				{"value":"2", "text":"Unlikely", "id":"probability_level_02"},
				{"value":"3", "text":"Possible", "id":"probability_level_03"},
				{"value":"4", "text":"Likely", "id":"probability_level_04"},
				{"value":"5", "text":"Certain", "id":"probability_level_05"}],
			"residual_risk_levels":[
				{"value":"1", "text":"Over controlled", "id":"residual_risk_level_01"},
				{"value":"2", "text":"Fully acceptable", "id":"residual_risk_level_02"},
				{"value":"3", "text":"Low", "id":"residual_risk_level_03"},
				{"value":"4", "text":"Moderate", "id":"residual_risk_level_04"},
				{"value":"5", "text":"Significant", "id":"residual_risk_level_05"},
				{"value":"6", "text":"Major", "id":"residual_risk_level_06"},
				{"value":"7", "text":"Severe", "id":"residual_risk_level_07"},
				{"value":"8", "text":"Catastrophic", "id":"residual_risk_level_08"},
				{"value":"9", "text":"Undecided", "id":"residual_risk_lever_09"}],
			"mitigation_effectiveness_levels":[
				{"value":"1", "text":"Excellent", "id":"mitigation_effectiveness_level_01"},
				{"value":"2", "text":"Very Good", "id":"mitigation_effectiveness_level_02"},
				{"value":"3", "text":"Good", "id":"mitigation_effectiveness_level_03"},
				{"value":"4", "text":"Fair", "id":"mitigation_effectiveness_level_04"},
				{"value":"5", "text":"Weak", "id":"mitigation_effectiveness_level_05"},
				{"value":"6", "text":"Ineffective", "id":"mitigation_effectiveness_level_06"},
				{"value":"7", "text":"Undecided", "id":"mitigation_effectiveness_level_07"}],
			"config_locked":false,
			"first_load":true,
			"backend":""
};
(function () {
    // module namespace

    var ts = streamwork;
    var ns = ts.module("com.leverx.risk_mgmt_svn_grc_copy_kh");

    // module imports
    var $ = jQuery;

    ns.methodClient = function (elementId, initialData, options) {
        var proxy, view, controller;

        proxy = {

            //----------------------------------------------- CREATE ASSESSMENT CONTAINER -------------------------------------------------
            //       creates a new assessment container on the database to save status visibility
            //---------------------------------------------------------------------------------------------------------------------

            create_assessment_container:function (options) {
                view.div.data('assessment_containers.' + options.id, options);
                var path = "assessment_containers", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    return_msg:'assessment_container_created'
                };
                //console.log("proxy: create assessment container...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                });
            }, //create_assessment_container
            //----------------------------------------------- UPDATE ASSESSMENT CONTAINER -------------------------------------------------
            //       updates a assessment container on the database to save status visibility
            //---------------------------------------------------------------------------------------------------------------------

            update_assessment_container:function (options) {
                view.div.data('assessment_containers.' + options.id, options);
                var path = "assessment_containers", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    return_msg:'assessment_container_updated'
                };
                //console.log("proxy: update assessment...");
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_assessment_container
            //------------------------------------------------- CREATE ASSESSMENT -------------------------------------------------
            //       creates a new risk and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------

            create_assessment:function (options) {
                view.div.data('assessments.' + options.id, options);
                var action_type = 'assessment_created', action_data = {
                    op:options.value["name"]
                }, path = "assessments", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    event:{
                        action:{
                            type:action_type
                        },
                        data:action_data
                    },
                    return_msg:'assessment_created'
                };
                //console.log("proxy: create assessment...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                });
            }, //create_assessment
            //------------------------------------------------- UPDATE ASSESSMENT -------------------------------------------------
            //       creates a new risk and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------
            update_assessment:function (options) {
                view.div.data('assessments.' + options.id, options);
                var action_type = 'assessment_updated', action_data = {
                    op:options.value["name"]
                }, path = "assessments", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    event:{
                        action:{
                            type:action_type
                        },
                        data:action_data
                    },
                    return_msg:'assessment_updated'
                };
                //console.log("proxy: update assessment...");
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_assessment

            get_assessment_for_close:function (assessment_id) {
                controller.clientChannel.publish({
                    type:"get_array_item",
                    data:{
                        path:"assessments",
                        id:assessment_id,
                        return_msg:'get_assessment_for_close_callback'
                    }
                });
            },
            //---------------------------------------------------- CREATE RISK ----------------------------------------------------
            //       creates a new risk and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------
            create_risk:function (options) {
                //view.div.data('risks.' + options.id, options);
                var action_type = 'risk_created', action_data = {
                        op:options.id
                    },
                    path = "risks",
                    data = {
                        path:[path],
                        id:options.id,
                        value:options.value,
                        event:{
                            action:{
                                type:action_type
                            },
                            data:action_data
                        },
                        return_msg:'risk_created'
                    };
                //console.log("proxy: create risk...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                });
            }, //create_risk
            //---------------------------------------------------- UPDATE RISK ----------------------------------------------------
            //       updates a risk and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------
            update_risk:function (options) {
                var action_type = 'risk_deleted', action_data = {
                    op:options.value["name"]
                }, path = "risks", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    event:{
                        action:{
                            type:action_type
                        },
                        data:action_data
                    },
                    return_msg:'risk_updated'
                };
                //console.log("proxy: create risk...");
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //create_risk
            //----------------------------------------------------- GET RISKS -----------------------------------------------------
            //       gets all existing risks from database
            //---------------------------------------------------------------------------------------------------------------------
            get_risks:function (message) {
                var path = "risks", data = {
                    path:["risks"],
                    return_msg:message
                };
                //console.log("proxy: get risks...");
                controller.clientChannel.publish({
                    type:'get_data',
                    data:data
                });
            }, //get_risk
            //------------------------------------------------ CREATE RISK CATEGORY -----------------------------------------------
            //       creates a new risk category and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------
            create_risk_category:function (options) {
                view.div.data('risk_categories.' + options.id, options);
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var action_type = 'risk_category_created', action_data = {
                    op:options.value["category_name"]
                }, path = "risk_categories", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    event:{
                        action:{
                            type:action_type
                        },
                        data:action_data
                    },
                    return_msg:'risk_category_created'
                };
                //console.log("proxy: create risk category...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                });
            }, //create_risk_categories
            //------------------------------------------------ GET RISK CATEGORIES -------------------------------------------------
            //       gets all existing risk categories from database
            //---------------------------------------------------------------------------------------------------------------------
            get_risk_categories:function () {
                //view.show_loading();
                //lipstick.addWaitOverlay(view.loading_target);
                var path = "risk_categories", data = {
                    path:[path],
                    return_msg:'get_risk_categories'
                };
                //console.log("proxy: get risk categories...");
                controller.clientChannel.publish({
                    type:'get_data',
                    data:data
                });
            }, //get_risk_categories
            //------------------------------------------------ GET RISK CATEGORIES -------------------------------------------------
            //       gets all existing risk categories from database
            //---------------------------------------------------------------------------------------------------------------------
            get_risk_categories_for_edit:function () {
                //view.show_loading();
                //lipstick.addWaitOverlay(view.loading_target);
                var path = "risk_categories", data = {
                    path:[path],
                    return_msg:'get_risk_categories_for_edit'
                };
                //console.log("proxy: get risk categories...");
                controller.clientChannel.publish({
                    type:'get_data',
                    data:data
                });
            }, //get_risk_categories
            //------------------------------------------------- CREATE ORG UNIT -----------------------------------------------------
            //       creates a new org unit and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------
            create_org_unit:function (options) {
                view.div.data('org_units.' + options.id, options);
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var action_type = 'org_unit_created', action_data = {
                    op:options.value["org_unit"]
                }, path = "org_units", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    event:{
                        action:{
                            type:action_type
                        },
                        data:action_data
                    },
                    return_msg:'org_unit_created'
                };
                //console.log("proxy: create org unit...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                });
            }, //create_org_unit
            //-------------------------------------------------- GET ORG UNITS ----------------------------------------------------
            //       gets all existing org units from database
            //---------------------------------------------------------------------------------------------------------------------
            get_org_units:function () {
                //lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var path = "org_units", data = {
                    path:[path],
                    return_msg:'get_org_units'
                };
                //console.log("proxy: get org units...");
                controller.clientChannel.publish({
                    type:'get_data',
                    data:data
                });
            }, //get_risk
            //------------------------------------------------- CREATE ORG UNIT -----------------------------------------------------
            //       creates a new org unit and saves it to the database
            //---------------------------------------------------------------------------------------------------------------------

            create_impact_category:function (options) {
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var action_type = 'impact_category_created', action_data = {
                    op:options.value["impact_category"]
                }, path = "impact_categories", data = {
                    path:[path],
                    id:options.id,
                    value:options.value,
                    return_msg:'impact_category_created'
                };
                //console.log("proxy: create impact category...");
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                })
            }, //create_impact_category
            //-------------------------------------------------- GET IMPACT CATEGORIES ----------------------------------------------------
            //       gets all existing impact categories from database
            //---------------------------------------------------------------------------------------------------------------------
            get_impact_categories:function () {
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var path = "impact_categories", data = {
                    path:[path],
                    return_msg:'get_impact_categories'
                };
                //console.log("proxy: get impact categories...");
                controller.clientChannel.publish({
                    type:'get_data',
                    data:data
                });
            }, //get_impact_categories
            //-------------------------------------------------- CREATE IMPACT LEVEL -------------------------------------------------
            //       Creates a new impact level
            //---------------------------------------------------------------------------------------------------------------------
            create_impact_level:function (options) {
                lipstick.addWaitOverlay(view.loading_target);
                var path = "impact_levels", data = {
                    path:[path],
                    id:options.id,
                    value:options,
                    return_msg:'impact_level_created'
                };
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                })
            }, //create_impact_level
            //-------------------------------------------------- DELETE IMPACT LEVEL -------------------------------------------------
            //       Deletes a  impact level
            //---------------------------------------------------------------------------------------------------------------------
            delete_impact_level:function (id) {
                var path = "impact_levels", data = {
                    path:[path],
                    id:id,
                    return_msg:'impact_deleted'
                };
                controller.clientChannel.publish({
                    type:'delete_array_item',
                    data:data
                })
            }, //delete_impact_level
            //-------------------------------------------------- UPDATE IMPACT LEVEL -------------------------------------------------
            //       Updates a  impact level
            //---------------------------------------------------------------------------------------------------------------------
            update_impact_level:function (options) {
                var path = "impact_levels", data = {
                    path:[path],
                    value:options,
                    id:options.id,
                    return_msg:'impact_updated'
                };
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_impact_level
            //-------------------------------------------------- CREATE PROBABILITY LEVEL -------------------------------------------------
            //       Creates a new probability level
            //---------------------------------------------------------------------------------------------------------------------
            create_probability_level:function (options) {
                lipstick.addWaitOverlay(view.loading_target);
                var path = "probability_levels", data = {
                    path:[path],
                    id:options.id,
                    value:options,
                    return_msg:'probability_level_created'
                };
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                })
            }, //create_probability_level
            //-------------------------------------------------- DELETE PROBABILITY LEVEL -------------------------------------------------
            //       Deletes a probability level
            //---------------------------------------------------------------------------------------------------------------------
            delete_probability_level:function (id) {
                var path = "probability_levels", data = {
                    path:[path],
                    id:id,
                    return_msg:'probability_deleted'
                };
                controller.clientChannel.publish({
                    type:'delete_array_item',
                    data:data
                })
            }, //delete_probability_level
            //-------------------------------------------------- UPDATE PROBABILITY LEVEL -------------------------------------------------
            //       Update a probability level
            //---------------------------------------------------------------------------------------------------------------------
            update_probability_level:function (options) {
                var path = "probability_levels", data = {
                    path:[path],
                    value:options,
                    id:options.id,
                    return_msg:'probability_updated'
                };
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_probability_level
            //ADDITIONAL CODING BY D053422
            //-------------------------------------------------- CREATE MITIGATION LEVEL -------------------------------------------------
            //       Creates a new mitigation level
            //---------------------------------------------------------------------------------------------------------------------
            create_mitigation_level:function (options) {
                lipstick.addWaitOverlay(view.loading_target);
                var data = {
                    path:"mitigation_effectiveness_levels",
                    id:options.id,
                    value:options,
                    return_msg:'mitigation_level_created'
                };
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                })
            }, //create_mitigation_level
            //-------------------------------------------------- DELETE MITIGATION LEVEL -------------------------------------------------
            //       Deletes a mitigation level
            //---------------------------------------------------------------------------------------------------------------------
            delete_mitigation_level:function (id) {
                var data = {
                    path:"mitigation_effectiveness_levels",
                    id:id,
                    return_msg:'mitigation_deleted'
                };
                controller.clientChannel.publish({
                    type:'delete_array_item',
                    data:data
                })
            }, //delete_mitigation_level
            //-------------------------------------------------- UPDATE MITIGATION LEVEL -------------------------------------------------
            //       Update a mitigation level
            //---------------------------------------------------------------------------------------------------------------------
            update_mitigation_level:function (options) {
                var data = {
                    path:"mitigation_effectiveness_levels",
                    value:options,
                    id:options.id,
                    return_msg:'mitigation_updated'
                };
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_mitigation_level
            //-------------------------------------------------- CREATE RESIDUAL LEVEL -------------------------------------------------
            //       Creates a new mitigation level
            //---------------------------------------------------------------------------------------------------------------------
            create_residual_level:function (options) {
                lipstick.addWaitOverlay(view.loading_target);
                var data = {
                    path:"residual_risk_levels",
                    id:options.id,
                    value:options,
                    return_msg:'residual_level_created'
                };
                controller.clientChannel.publish({
                    type:'insert_array_item',
                    data:data
                })
            }, //create_mitigation_level
            //-------------------------------------------------- DELETE RESIDUAL LEVEL -------------------------------------------------
            //       Deletes a residual level
            //---------------------------------------------------------------------------------------------------------------------
            delete_residual_level:function (id) {
                var data = {
                    path:"residual_risk_levels",
                    id:id,
                    return_msg:'residual_deleted'
                };
                controller.clientChannel.publish({
                    type:'delete_array_item',
                    data:data
                })
            }, //delete_residual_level
            //-------------------------------------------------- UPDATE RESIDUAL LEVEL -------------------------------------------------
            //       Update a residual level
            //---------------------------------------------------------------------------------------------------------------------
            update_residual_level:function (options) {
                var data = {
                    path:"residual_risk_levels",
                    value:options,
                    id:options.id,
                    return_msg:'residual_updated'
                };
                controller.clientChannel.publish({
                    type:'update_array_item',
                    data:data
                });
            }, //update_residual_level
            //END OF ADDITIONAL CODING

            //-------------------------------------------------- UPDATE AGGREGATION METHOD -------------------------------------------------
            //       updates the selected aggregation method
            //---------------------------------------------------------------------------------------------------------------------
            update_selected_aggregation_method:function (options) {
                var path = "aggregation_method", data = {
                    path:[path],
                    value:options.value,
                    return_msg:'aggregation_method_updated'
                };
                controller.clientChannel.publish({
                    type:"set_data",
                    data:data
                })
            }, //update_selected_aggregation_method
            //-------------------------------------------------- SET CONFIG SCREEN LOCKED ---------------------------------------------
            //       locks the configuration screen if anybody is doing the configuration
            //---------------------------------------------------------------------------------------------------------------------
            set_configuration_lock:function (options) {
                var path = "config_locked", data = {
                    path:[path],
                    value:options,
                    return_msg:'config_lock'
                };
                controller.clientChannel.publish({
                    type:"set_data",
                    data:data
                })
            }, //set_cinfiguration_locked
            //-------------------------------------------------- GET CONFIG SCREEN LOCKED ---------------------------------------------
            //       takes a look if the configuration screen is already opened by another user
            //---------------------------------------------------------------------------------------------------------------------
            get_configuration_lock:function () {
                var path = "config_locked", data = {
                    path:[path],
                    return_msg:'get_config_lock'
                };
                controller.clientChannel.publish({
                    type:"get_data",
                    data:data
                })
            }, //get_configuration_locked
            //-------------------------------------------------- SET HOST FOR CONNECTION ---------------------------------------------
            //       sets the host for a connection to the backend
            //---------------------------------------------------------------------------------------------------------------------
            set_host:function (options) {
                var path = "backend",
                    data = {
                        path:[path],
                        value:options,
                        return_msg:'host_set'
                    };
                controller.clientChannel.publish({
                    type:"set_data",
                    data:data
                })
            }, //set host
            //-------------------------------------------------- GET HOST FOR CONNECTION ---------------------------------------------
            //       gets the host for a connection to the backend
            //---------------------------------------------------------------------------------------------------------------------
            get_host:function () {
                var path = "backend",
                    data = {
                        path:[path],
                        return_msg:'host_got'
                    };
                controller.clientChannel.publish({
                    type:"get_data",
                    data:data
                })
            }, //get host
            //-------------------------------------------------- UPDATE AFTER FIRST LOAD ---------------------------------------------
            //       updates the indicator, that shows if this is the first load
            //---------------------------------------------------------------------------------------------------------------------
            update_first_loaded:function (options) {
                var path = "first_load",
                    data = {
                        path:[path],
                        value:options,
                        return_msg:'first_load_updated'
                    };
                controller.clientChannel.publish({
                    type:"set_data",
                    data:data
                })
            }, //get host

            //ADDITINAL CODING BY D053422
            update_risk_table_header:function (new_title) {
                var path = "risk_table_header",
                    data = {
                        path:[path],
                        value:new_title,
                        return_msg:'controller.risk_table_header_updated'
                    };
                controller.clientChannel.publish({
                    type:"set_data",
                    data:data
                })
            },

            get_risk_table_header:function () {
                var path = "risk_table_header",
                    data = {
                        path:[path],
                        return_msg:'controller.risk_table_header_got'
                    };
                controller.clientChannel.publish({
                    type:"get_data",
                    data:data
                })
            }
            //END OF ADDITIONAL CODING

        };//proxy


        view = {

            div:$("#" + elementId),
            last_prob_id:0,
            last_probability_used:1,
            lst_impact_id:0,
            last_impact_level_used:1,
            last_mitigation_id:0,
            last_mitigation_level_used:1,
            last_residual_id:0,
            last_residual_level_used:1,

            loading_target:null,

            impacts:[],
            //----------------------------------------------------- MAIN VIEW -----------------------------------------------------
            //       displaying the main view of the business method
            //---------------------------------------------------------------------------------------------------------------------
            main_div_id:elementId + '_main',
            risk_header_title_text:'',
            risk_header_title_id:elementId + '_risk_header_title',

            show_main_view:function () {
                var main_div_string = '<div>' +
                    //'<div class="risk_table_head">Risks</div>' +
                    '<div height="34px" style = "display: inline-block;">' +
                    '<div class="table_head_left"></div>' +
                    //'<div class="table_head_middle2 resizable_head">Risks</div>' +
                    '<div class="table_head_middle2 resizable_head">' +
                    '<div class="risk_table_header changeable_title" id="' + view.risk_header_title_id + '" title="Click to edit�">' + view.risk_header_title_text + '</div>' +
                    '</div>' +
                    '<div class="table_head_right"></div>' +
                    '</div>' +
                    '<div height="31px" style = "display: inline-block;">' +
                    '<div class="table_body_left"></div>' +
                    '<div class="table_body_middle2 resizable_body">' + //class="risk_table_bottom" style="height:34px !important;" >' +
                    '<table width="100%" style="text-align:center;">' +
                    '<th width="12%">Name</th>' +
                    '<th width="15%">Description</th>' +
                    '<th width="16%">Category</th>' +
                    '<th width="16%">Organization Unit</th>' +
                    '<th width="20%"><div style="text-align:center;">Impacts</div><div><table width="100%"><tr><th width="50%">Name</th><th width="50%">Category</th></tr></table></div></th>' +
                    '</table>' +
                    '</div>' +
                    '<div class="table_body_right"></div>' +
                    '</div>' +
                    //'<div class="risk_table_bottom_right"></div>'+
                    //'</div>'+
                    '<div id="placeholder_new_risks"></div>' +
                    //'<div class="risk_table_bottom"></div>'+
                    '<div style = "display: inline-block;">' +
                    '<div class="table_body_left"></div>' +
                    //'<div class="create_risk_assessment_link" id="new_risk_link">Click here to create new Risk</div>'+
                    '<div class="table_body_middle2 resizable_body" id="new_risk_link_' + elementId + '">' +
                    '<div class="create_risk_assessment_link">Click here to create new Risk</div>' +
                    '</div>' +
                    '<div class="table_body_right"></div>' +
                    '</div>' +
                    //'</div>' +
                    '<div class="break resizable_body"></div>' +
                    '<div>' +
                    //'</div>' +
                    '<div id="assessments">' +
                    //'<div class="risk_table_head">Assessments</div>' +
                    '<div style = "display: inline-block;">' +
                    '<div class="table_head_left"></div>' +
                    '<div class="table_head_middle2 resizable_head">' +
                    '<div class="risk_table_header">Assessments</div> ' +
                    '</div>' +
                    '<div class="table_head_right"></div>' +
                    '</div>' +
                    '<div class="assessment_placeholder" id="placeholder_create_new_assessment">' +
                    '</div>' +
                    '<div style = "display: inline-block;">' +
                    //'<div class="create_risk_assessment_link" id="new_assessment_link" >Click here to create new Assessment</div>'+
                    '<div class="table_body_left"></div>' +
                    '<div class="table_body_middle2 resizable_body" id="new_assessment_link_' + elementId + '">' +
                    '<div class="create_assessment_link">Click here to create new Assessment</div>' +
                    '</div>' +
                    '<div class="table_body_right"></div>' +
                    '</div>' +
                    '</div>'


                $(view.div[0]).append(main_div_string);

                view._viewResizeHandler();

                var action_menu_properties_div = $('<div class="square_option">' +
                    '<div class="square_text">' +
                    '<span class="popup_menu_text" style="position: relative;">' +
                    '<div id="iconview_item_menu_edit" class="menuIcon"></div>Properties' +
                    '</span>' +
                    '</div>' +
                    '</div>');
                var action_menu_export_div = $('<div class="square_option">' +
                    '<div class="square_text">' +
                    '<span class="popup_menu_text" style="position: relative;">' +
                    '<div id="iconview_item_menu_export" class="menuIcon"></div>CSV Export' +
                    '</span>' +
                    '</div>' +
                    '</div>');

                var session_id = elementId;
                var index = session_id.indexOf("_");
                index = session_id.indexOf("_", index + 1);
                index = session_id.indexOf("_", index + 1);
                session_id = session_id.substring(index + 1);
                session_id = 'item_action_' + session_id;
                var item_heading_div = $('#' + session_id);
                var action_menu_div = $('.itemActions');

                //only for standalone mode
                var set_properties_and_export = function () {
                    action_menu_div.click(function () {
                        var action_menu_entries = $('#action_menu').children().children().children();
                        var action_menu_reorder = [];
                        var count = 0;
                        for (var i = 0; i < action_menu_entries.length; i++) {
                            if (i > 1) {
                                action_menu_reorder.push(action_menu_entries[i]);
                                count++;
                            }
                        }
                        /*for ( var i = 0; i < count; i++ ){
                         action_menu_entries.pop();
                         }*/
                        action_menu_entries.push(action_menu_properties_div);
                        action_menu_entries.push(action_menu_export_div);
                        /*for ( var i = 0; i < action_menu_reorder.length; i++){
                         action_menu_entries.push(action_menu_reorder[i]);
                         }*/

                        if ($('#action_menu').find("#iconview_item_menu_edit").length == 0) {
                            $('#action_menu').children().children().append(action_menu_properties_div);
                            action_menu_properties_div.click(function () {
                                view.show_configuration();
                                //alert("test");
                            });
                        }
                        if ($('#action_menu').find("#iconview_item_menu_export").length == 0) {
                            $('#action_menu').children().children().append(action_menu_export_div);
                            action_menu_export_div.click(function () {
                                view.show_csv_export();
                            });
                        }
                    });//action menu called ==> add properties menu entry
                };

                //23.12.2011
                $('#new_risk_link_' + elementId).click(function () {
                    //$('#loading').show();
                    view.show_new_risk();
                });//new_risk_clicked
                $('#new_assessment_link_' + elementId).click(function () {
                    view.create_new_assessment();
                });//new_assessment_clicked

                //ADDED BY D053422
                $('#' + view.risk_header_title_id).hover(
                    function () {
                        var riskHeaderTitleName = $('#' + view.risk_header_title_id);
                        riskHeaderTitleName.addClass('title_editable');
                    }, //hover start
                    function () {
                        var riskHeaderTitleName = $('#' + view.risk_header_title_id);
                        riskHeaderTitleName.removeClass('title_editable');
                    }//hover ended
                );//riskHeaderTitleName.hover

                $("#" + view.risk_header_title_id).editable(function (value, settings) {
                    if (!value || !value.length || $.trim(value) === '') {
                        //$(this).text(this.revert);
                        return;
                    }
                    //controller.update_title(value, true);
                }, {
                    type:'text',
                    onreadytoedit:function () {

                    },
                    onfinishededit:function () {
                        if ($(this).is('.title_editable')) {
                            $(this).removeClass('title_editable');
                        }
                        $(this).css('color', '#333333');
                        var inputvalue = $(this).text();
                        $('#' + view.risk_header_title_id).val(inputvalue);
                        proxy.update_risk_table_header(inputvalue);
                    },
                    //height: '15px',
                    width:'130px',
                    //cssclass: 'buttonInplaceEdit',
                    tooltip:'Click to edit...',
                    placeholder:"Risks"
                });//edit Risks Header Title
                //END ADDITIONAL CODING
                if (streamwork.getViewerId() == options.itemCreatorUuid && controller.first_load == true) {
                    var connection_config_div = $('<div width="100%">' +
                        '<table>' +
                        '<td width="20%">' +
                        '<img src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/connections.png" width="50px" alt="Grafik">' +
                        '</td>' +
                        '<td>' +
                        '<div>Do you want to connect this Business Method to a SAP GRC?</div>' +
                        '<div>You need to provide a host on which the services are configured and activated.</div>' +
                        '<div style="margin-top:10px;">' +
                        '<table>' +
                        '<tr>' +
                        '<td width="80%">' +
                        '<table>' +
                        '<tr width="100%">' +
                        '<td width="20%"><div>Host:</div></td>' +
                        '<td width="80%"><input id="host" type="text" width="100%"></td>' +
                        '</tr>' +
                        '</table>' +
                        '</td>' +
                        '<td width="20%">' +
                        '<table>' +
                        '<tr width="100%">' +
                        '<td width="20%"><div>Port:</div></td>' +
                        '<td width="80%"><input id="port" type="text" width="50px"></td>' +
                        '</tr>' +
                        '</table>' +
                        '</td>' +
                        '</tr>' +
                        '</table>' +
                        '</div>' +
                        '<td>' +
                        '</table>' +
                        '</div>');
                    var finishFlag = false;
                    var d = lipstick.showMethodDialog(connection_config_div, {
                        title:'SAP Integration',
                        ok:function () {
                            lipstick.addWaitOverlay(connection_config_div);
                            var message = this;
                            var host = jQuery('#host').val();
                            var port = jQuery('#port').val();
                            if (host == '' || port == '') {
                                lipstick.alert('Please fill in both the Host and Port fields');
                                lipstick.removeWaitOverlay(connection_config_div);
                                return false;
                            }
                            var errorFlag = false;
                            /*
                             var timer_error = setTimeout(function () {
                             if (!errorFlag) {
                             lipstick.alert('Sorry, but host is temporary unavailable');
                             }
                             errorFlag = true;
                             lipstick.removeWaitOverlay(connection_config_div);
                             }, 5000);
                             */
                            var timer_dialog = setTimeout(function () {
                                if (finishFlag) {
                                    message.find('.cancel-button').trigger('click');
                                }
                            }, 1000);
                            streamwork._org_units_callback = function () {
                                if (!errorFlag) { //no errors received yet
                                    var host = jQuery('#host').val() + ':' + jQuery('#port').val();
                                    controller.host = host;
                                    controller.set_host(host);
                                    finishFlag = true;
                                    errorFlag = true;
                                    lipstick.removeWaitOverlay(connection_config_div);
                                }
                            }
                            //TODO: find out if this request is necessary. Seems like it's used here only to test connectivity
                            setTimeout(streamwork._org_units_callback, 500);
                            /*$.getJSONP({
                                url:'http://' + jQuery('#host').val() + ':' + jQuery('#port').val() + '/sap/resources/orgs_units?streamwork._org_units_callback=callback',
                                timeout:5000,
                                jsonp:streamwork._org_units_callback,
                                complete:function (jqXHR, textStatus) {
                                    if (!errorFlag) { //no errors received yet
                                        lipstick.alert('Unable to connect to GRC system. Please check your entries for Host and Port.');
                                        errorFlag = true;
                                        lipstick.removeWaitOverlay(connection_config_div);
                                    }
                                }
                            })*/
                            return false;
                        },
                        okLabel:"Connect",
                        cancelLabel:"Standalone",
                        cancel:function () {
                            if (!finishFlag) {
                                controller.update_first_load();
                                set_properties_and_export();
                            }
                        },
                        width:600
                    }, {
                        position:[150, null]
                    });
                }//first load
                else {
                    if (controller.host == null) {
                        set_properties_and_export();
                    }
                }
            }, //show_main_view
            //----------------------------------------------------- RESIZE HANDLER ----------------------------------------------
            //
            //-----------------------------------------------------------------------------------------------------------------
            _viewResizeHandler:function () {
                if (controller.user_agent == 'msie') {
                    $('.resizable_head').width(view.div.width() - 13);
                    $('.resizable_body').width(view.div.width() - 6);
                    $('.resizable_body2').width(view.div.width() - 1);
                }
                else {
                    $('.resizable_head').width(view.div.width() - 13);
                    $('.resizable_body').width(view.div.width() - 5);
                    $('.resizable_body2').width(view.div.width());
                }
            }, //_viewResizeHandler
            //----------------------------------------------------- ADD IMPACT CONFIG ENTRIES --------------------------------------------------
            //TODO
            //---------------------------------------------------------------------------------------------------------------------
            add_impact_config_entries:function (config_impacts_div, disabled) {
                for (var i = 0; i < controller.new_impact_levels.length; i++) {
                    var value = controller.new_impact_levels[i].value;
                    var text = controller.new_impact_levels[i].text;
                    var remove_id = "remove_" + generate_id();
                    var impact_div = $('<tr height="28px"id="tr_' + i + '" class="config_table_row config_impact">' +
                        '<td width="60px" style="text-align:center;">' +
                        value +
                        '</td>' +
                        '<td width="120px" style="text-align:center;"><input class="bind_impact_level" ' +
                        disabled +
                        ' type="text" id="' +
                        i +
                        '" value="' +
                        text +
                        '"></td>' +
                        '<td width="26px" id="' +
                        remove_id +
                        '"><div class="remove_entry" ></div></td>' +
                        '<tr>')
                    $('#' + remove_id, impact_div).click(function () {
                        var table_entry = this.parentNode;
                        var impact_value = table_entry.id.substring(table_entry.id.indexOf("_") + 1) - (-1);
                        var impact_id;
                        for (i = 0; i < controller.new_impact_levels.length; i++) {
                            if (controller.new_impact_levels[i].value == impact_value) {
                                impact_id = controller.new_impact_levels[i].id;
                                break;
                            }
                        }
                        $('.config_impact').hide();
                        controller.remove_impact(impact_value, impact_id);
                        view.last_impact_level_used--;
                        view.last_impact_id--;
                        config_impacts_div = view.add_impact_config_entries(config_impacts_div, disabled);
                    })

                    $('.add_impact_level_container', config_impacts_div).remove('#add_level')
                    $('#impact_table', config_impacts_div).append(impact_div);
                    view.last_impact_level_used = value;
                    view.last_impact_id = value - 1;
                }//for
                if (disabled == "") {
                    $('.config_table_row', config_impacts_div).hover(function () {
                            var remove_div = $('.remove_entry', this);
                            remove_div.removeClass("remove_entry");
                            remove_div.addClass("remove_entry_show");
                        }, //hover start
                        function () {
                            var remove_div = $('.remove_entry_show', this);
                            remove_div.removeClass("remove_entry_show");
                            remove_div.addClass("remove_entry");
                        }//hover end
                    )//hover
                }
                return config_impacts_div;

            }, //add_impact_config_entries
            //----------------------------------------------------- ADD PROB CONFIG ENTRIES --------------------------------------------------
            //TODO
            //---------------------------------------------------------------------------------------------------------------------
            add_prob_config_entries:function (config_prob_div, disabled) {
                view.last_probability_used = 0;
                view.last_prob_id = 0;
                for (var i = 0; i < controller.new_probability_levels.length; i++) {
                    var value = controller.new_probability_levels[i].value;
                    var text = controller.new_probability_levels[i].text;
                    var remove_id = "remove_" + generate_id();
                    var prob_div = $('<tr height="28px" id="tr_' + i + '" class="config_table_row config_prob">' +
                        '<td width="60px" style="text-align:center;">' +
                        value +
                        '</td>' +
                        '<td width="120px" style="text-align:center;"><input class="bind_prob_level" ' +
                        disabled +
                        ' type="text" id="' +
                        i +
                        '" value="' +
                        text +
                        '"></td>' +
                        '<td width="26px" ><div id="' +
                        remove_id +
                        '" class="remove_entry"></div></td>' +
                        '<tr>')

                    $('#' + remove_id, prob_div).click(function () {
                        var table_entry = this.parentNode.parentNode;
                        var prob_value = table_entry.id.substring(table_entry.id.indexOf("_") + 1) - (-1);
                        var prob_id;
                        for (i = 0; i < controller.new_probability_levels.length; i++) {
                            if (controller.new_probability_levels[i].value == prob_value) {
                                prob_id = controller.new_probability_levels[i].id;
                                break;
                            }
                        }
                        $('.config_prob').hide();
                        controller.remove_probability(prob_value, prob_id);
                        view.last_probability_used--;
                        view.last_prob_id--;
                        config_prob_div = view.add_prob_config_entries(config_prob_div, disabled);
                    })

                    $('.add_prob_level_container', config_prob_div).remove('#add_prob_level')
                    $('#prob_table', config_prob_div).append(prob_div);
                    view.last_probability_used = value;
                    view.last_prob_id = value - 1;
                }//for
                if (disabled == "") {
                    $('.config_table_row', config_prob_div).hover(function () {
                            var remove_div = $('.remove_entry', this);
                            remove_div.removeClass("remove_entry");
                            remove_div.addClass("remove_entry_show");
                        }, //hover start
                        function () {
                            var remove_div = $('.remove_entry_show', this);
                            remove_div.removeClass("remove_entry_show");
                            remove_div.addClass("remove_entry");
                        }//hover end
                    )//hover
                }
                return config_prob_div;
            }, //add_prob_config_entries
            //--------------------------------------------------- ADD MITIGATION CONFIG ENTRIES -------------------------------------------------
            //  ADDED BY D053422
            //---------------------------------------------------------------------------------------------------------------------
            add_mitigation_config_entries:function (config_mitigation_div, disabled) {
                for (var i = 0; i < controller.new_mitigation_levels.length; i++) {
                    var value = controller.new_mitigation_levels[i].value;
                    var text = controller.new_mitigation_levels[i].text;
                    var remove_id = "remove_" + generate_id();
                    var mitigation_div = $('<tr height="28px"id="tr_' + i + '" class="config_table_row config_mitigation">' +
                        '<td width="60px" style="text-align:center;">' +
                        value +
                        '</td>' +
                        '<td width="120px" style="text-align:center;"><input class="bind_mitigation_level" ' +
                        disabled +
                        ' type="text" id="' +
                        i +
                        '" value="' +
                        text +
                        '"></td>' +
                        '<td width="26px" id="' +
                        remove_id +
                        '"><div class="remove_entry" ></div></td>' +
                        '<tr>')
                    $('#' + remove_id, mitigation_div).click(function () {
                        var table_entry = this.parentNode;
                        var mitigation_value = table_entry.id.substring(table_entry.id.indexOf("_") + 1) - (-1);
                        var mitigation_id;
                        for (i = 0; i < controller.new_mitigation_levels.length; i++) {
                            if (controller.new_mitigation_levels[i].value == mitigation_value) {
                                mitigation_id = controller.new_mitigation_levels[i].id;
                                break;
                            }
                        }
                        $('.config_mitigation').hide();
                        controller.remove_mitigation(mitigation_value, mitigation_id);
                        view.last_mitigation_level_used--;
                        view.last_mitigation_id--;
                        config_mitigation_div = view.add_mitigation_config_entries(config_mitigation_div, disabled);
                    })

                    $('.add_mitigation_level_container', config_mitigation_div).remove('#add_level')
                    $('#mitigation_table', config_mitigation_div).append(mitigation_div);
                    view.last_mitigation_level_used = value;
                    view.last_mitigation_id = value - 1;
                }//for
                if (disabled == "") {
                    $('.config_table_row', config_mitigation_div).hover(function () {
                            var remove_div = $('.remove_entry', this);
                            remove_div.removeClass("remove_entry");
                            remove_div.addClass("remove_entry_show");
                        }, //hover start
                        function () {
                            var remove_div = $('.remove_entry_show', this);
                            remove_div.removeClass("remove_entry_show");
                            remove_div.addClass("remove_entry");
                        }//hover end
                    )//hover
                }
                return config_mitigation_div;

            }, //add_mitigation_config_entries
            //--------------------------------------------------- ADD RESIDUAL CONFIG ENTRIES -------------------------------------
            //  ADDED BY D053422
            //---------------------------------------------------------------------------------------------------------------------
            add_residual_config_entries:function (config_residual_div, disabled) {
                for (var i = 0; i < controller.new_residual_levels.length; i++) {
                    var value = controller.new_residual_levels[i].value;
                    var text = controller.new_residual_levels[i].text;
                    var remove_id = "remove_" + generate_id();
                    var residual_div = $('<tr height="28px"id="tr_' + i + '" class="config_table_row config_residual">' +
                        '<td width="60px" style="text-align:center;">' +
                        value +
                        '</td>' +
                        '<td width="120px" style="text-align:center;"><input class="bind_residual_level" ' +
                        disabled +
                        ' type="text" id="' +
                        i +
                        '" value="' +
                        text +
                        '"></td>' +
                        '<td width="26px" id="' +
                        remove_id +
                        '"><div class="remove_entry" ></div></td>' +
                        '<tr>')
                    $('#' + remove_id, residual_div).click(function () {
                        var table_entry = this.parentNode;
                        var residual_value = table_entry.id.substring(table_entry.id.indexOf("_") + 1) - (-1);
                        var residual_id;
                        for (i = 0; i < controller.new_residual_levels.length; i++) {
                            if (controller.new_residual_levels[i].value == residual_value) {
                                residual_id = controller.new_residual_levels[i].id;
                                break;
                            }
                        }
                        $('.config_residual').hide();
                        controller.remove_residual(residual_value, residual_id);
                        view.last_residual_level_used--;
                        view.last_residual_id--;
                        config_residual_div = view.add_residual_config_entries(config_residual_div, disabled);
                    })

                    $('.add_residual_level_container', config_residual_div).remove('#add_level')
                    $('#residual_table', config_residual_div).append(residual_div);
                    view.last_residual_level_used = value;
                    view.last_residual_id = value - 1;
                }//for
                if (disabled == "") {
                    $('.config_table_row', config_residual_div).hover(function () {
                            var remove_div = $('.remove_entry', this);
                            remove_div.removeClass("remove_entry");
                            remove_div.addClass("remove_entry_show");
                        }, //hover start
                        function () {
                            var remove_div = $('.remove_entry_show', this);
                            remove_div.removeClass("remove_entry_show");
                            remove_div.addClass("remove_entry");
                        }//hover end
                    )//hover
                }
                return config_residual_div;
            }, //add_mitigation_config_entries
            //----------------------------------------------------- CONFIGURATION --------------------------------------------------
            //
            //---------------------------------------------------------------------------------------------------------------------
            show_configuration:function () {

                controller.get_configuration_locked();
                if (controller.config_locked == true) {
                    lipstick.alert("Another User is already changing the configuration.");
                    return;
                }//
                else {
                    controller.set_config_locked();
                }

                var disabled = "";

                for (var i = 0; i < controller.assessments.length; i++) {
                    if (controller.assessments[i].status != "in planning") {
                        disabled = 'disabled="disabled"';
                        break;
                    }//if at least one assessment has already been started
                }
                ;//lookup if assessment hast already been started
                var config_div_id = elementId + '_config';
                var configuration_div = $('<div class="configuration_div" id="' + config_div_id + '">' +
                    '<table class="config_table">' +
                    '<tr>' +
                    '<td valign="top" width="50%" id="impact_level_configuration"></td>' +
                    '<td valign="top" width="50%" id="prob_level_configuration"></td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td valign="top" width="50%" id="mitigation_level_configuration"></td>' +
                    '<td valign="top" width="50%" id="residual_level_configuration"></td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td width="50%"><div id="aggregation_method_configuration"></div></td>' +
                    '<td width="50%">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '</div>');
                view.loading_target = configuration_div;

                controller.new_impact_levels = controller.clone(controller.impact_levels);
                controller.new_probability_levels = controller.clone(controller.probability_levels);
                controller.new_mitigation_levels = controller.clone(controller.mitigation_effectiveness_levels);
                controller.new_residual_levels = controller.clone(controller.residual_risk_levels);
                //**********************************************************************************************
                //                    Impact Level Configuration
                //**********************************************************************************************
                var config_impact_div_id = config_div_id + '_impact';
                var config_impacts_div = $('<div class="config_impacts_div">' +
                    '<fieldset id="' +
                    config_impact_div_id +
                    '" class="config_container">' +
                    '<legend>Impact Level</legend>' +
                    '<div>' +
                    '<table width="240px" id="impact_table">' +
                    '<tr">' +
                    '<th width="60px" style="text-align:center;">Impact Level</th>' +
                    '<th width="120px" style="text-align:center;">Impact Level Text</th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '<table width="240px">' +
                    '<tr">' +
                    '<th width="60px">&nbsp;</th>' +
                    '<th width="120px"><div id="add_level" ' +
                    disabled +
                    ' class="grc_link">Add Impact Level</div></th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '</fieldset>' +
                    '</div>');

                config_impacts_div = view.add_impact_config_entries(config_impacts_div, disabled);

                $(".bind_impact_level", config_impacts_div).bind("change", function () {
                    controller.new_impact_levels[this.id]["text"] = this.value;
                    controller.impact_levels_to_change.push(controller.new_impact_levels[this.id]);
                    //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                })//bind_change
                var add_impact_level_div_id = config_impact_div_id + '_add';


                $('#add_level', config_impacts_div).click(function () {
                    if (disabled == "") {
                        view.last_impact_level_used++;
                        view.last_impact_id++;
                        //add_impact_level = $('#add_level', config_impacts_div);
                        //$('.add_impact_level_container', config_impacts_div).remove('#add_level');
                        var last_entry = $('.bind_create_impact_level', config_impacts_div);
                        last_entry.removeClass('.bind_create_impact_level');
                        last_entry.addClass('bind_impact_level');
                        var remove_id = "remove_" + generate_id();
                        var impact_div = $('<tr height="28px" id="' + view.last_impact_id + '" config_table_row>' +
                            '<td width="60px" style="text-align:center;">' +
                            view.last_impact_level_used +
                            '</td>' +
                            '<td width="120px" style="text-align:center;"><input class="bind_create_impact_level" type="text" id="' +
                            view.last_impact_id +
                            '"></td>' +
                            '<td width="26px" id="' +
                            remove_id +
                            '"><div class="remove_entry" ></div></td>' +
                            '</td>' +
                            '<tr>')

                        impact_div.hover(function () {
                                var remove_div = $('.remove_entry', this);
                                remove_div.removeClass("remove_entry");
                                remove_div.addClass("remove_entry_show");
                            }, //hover start
                            function () {
                                var remove_div = $('.remove_entry_show', this);
                                remove_div.removeClass("remove_entry_show");
                                remove_div.addClass("remove_entry");
                            }//hover end
                        )//hover
                        $('.bind_create_impact_level', impact_div).bind("change", function () {
                            var old_last = $('.bind_create_impact_level', impact_div);
                            old_last.removeClass('bind_create_impact_level');
                            old_last.addClass('bind_impact_level');

                            old_last.unbind("change").bind("change", function () {
                                controller.new_impact_levels[this.id].text = this.value;
                                //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                            })//existing entry changed
                            var impact_level = {
                                "value":++this.id,
                                "text":this.value,
                                "id":generate_id()
                            }//impact_level
                            controller.new_impact_levels[this.id - 1] = impact_level;
                            //controller.create_impact_level(impact_level);
                            controller.impact_levels_to_create.push(impact_level);
                            //alert("impact level " + controller.impact_levels[this.id].value + " " + controller.impact_levels[this.id].text);
                        })//new_entry changed
                        $('#impact_table', config_impacts_div).append(impact_div);
                    }
                });//add_impact_level.click
                //configuration_div.append(config_impacts_div);
                $('#impact_level_configuration', configuration_div).append(config_impacts_div);
                //**********************************************************************************************
                //                    Probability Level Configuration
                //**********************************************************************************************
                var add_probability_level = $('<div id="add_prob_level" ' + disabled + ' class="grc_link">Add Probability Level</div>');
                var config_prob_div_id = config_div_id + '_prob';
                var config_prob_div = $('<div class="config_prob_div">' +
                    '<fieldset id="' +
                    config_prob_div_id +
                    '" class="config_container">' +
                    '<legend>Probability Level</legend>' +
                    '<div>' +
                    '<table width="240px" id="prob_table">' +
                    '<tr">' +
                    '<th width="60px" style="text-align:center;">Probability Level</th>' +
                    '<th width="120px" style="text-align:center;">Probability Level Text</th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '<table width="240px">' +
                    '<tr">' +
                    '<th width="60px">&nbsp;</th>' +
                    '<th width="120px"><div id="add_prob_level" ' +
                    disabled +
                    ' class="grc_link">Add Probability Level</div></th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '</fieldset>' +
                    '</div>');

                config_prob_div = view.add_prob_config_entries(config_prob_div, disabled);

                $(".bind_prob_level", config_prob_div).bind("change", function () {
                    controller.new_probability_levels[this.id]["text"] = this.value;
                    controller.probability_to_change.push(controller.new_probability_levels[this.id]);
                    //alert("changed to: " + controller.probability_levels[this.id]["text"]);
                })//bind_change
                var add_prob_level_div_id = config_prob_div_id + '_add';


                $('#add_prob_level', config_prob_div).click(function () {
                    if (disabled == "") {
                        view.last_probability_used++;
                        view.last_prob_id++;
                        var last_entry = $('.bind_create_prob_level', config_prob_div);
                        last_entry.removeClass('.bind_create_prob_level');
                        last_entry.addClass('bind_prob_level');
                        var remove_id = "remove_" + generate_id();
                        var prob_div = $('<tr height="28px" id="' + view.last_prob_id + '" config_table_row>' +
                            '<td width="60px" style="text-align:center;">' +
                            view.last_probability_used +
                            '</td>' +
                            '<td width="120px" style="text-align:center;"><input class="bind_create_prob_level" type="text" id="' +
                            view.last_prob_id +
                            '"></td>' +
                            '<td width="26px" ><div id="' +
                            remove_id +
                            '" class="remove_entry"></div></td>' +
                            '</td>' +
                            '<tr>')
                        prob_div.hover(function () {
                                var remove_div = $('.remove_entry', this);
                                remove_div.removeClass("remove_entry");
                                remove_div.addClass("remove_entry_show");
                            }, //hover start
                            function () {
                                var remove_div = $('.remove_entry_show', this);
                                remove_div.removeClass("remove_entry_show");
                                remove_div.addClass("remove_entry");
                            }//hover end
                        )//hover
                        $('.bind_create_prob_level', prob_div).bind("change", function () {
                            var old_last = $('.bind_create_prob_level', prob_div);
                            old_last.removeClass('bind_create_prob_level');
                            old_last.addClass('bind_prob_level');

                            old_last.unbind("change").bind("change", function () {
                                controller.new_probability_levels[this.id].text = this.value;
                                //alert("changed to: " + controller.probability_levels[this.id]["text"]);
                            })//existing entry changed
                            var prob_level = {
                                "value":++this.id,
                                "text":this.value,
                                "id":generate_id()
                            }//prob_level
                            controller.new_probability_levels[this.id - 1] = prob_level;
                            //controller.create_probability_level(prob_level);
                            controller.probability_to_create.push(prob_level);
                            //alert("prob level " + controller.probability_levels[this.id].value + " " + controller.probability_levels[this.id].text);
                        })//new_entry changed
                        $('#prob_table', config_prob_div).append(prob_div);
                    }
                });//add_prob_level.click
                //configuration_div.append(config_probs_div);
                $('#prob_level_configuration', configuration_div).append(config_prob_div);

                //**********************************************************************************************
                //                    Mitigation Effectiveness Level Configuration
                //**********************************************************************************************
                var config_mitigation_div_id = config_div_id + '_mitigation';
                var config_mitigation_div = $('<div class="config_mitigation_div">' +
                    '<fieldset id="' +
                    config_mitigation_div_id +
                    '" class="config_container">' +
                    '<legend>Mitigaion Effectiveness Level</legend>' +
                    '<div>' +
                    '<table width="240px" id="mitigation_table">' +
                    '<tr">' +
                    '<th width="60px" style="text-align:center;">Level</th>' +
                    '<th width="120px" style="text-align:center;">Mitigation Effectiveness Level Text</th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '<table width="240px">' +
                    '<tr">' +
                    '<th width="60px">&nbsp;</th>' +
                    '<th width="120px"><div id="add_level" ' +
                    //disabled +
                    ' class="grc_link">Add Mitigation Effectiveness Level</div></th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '</fieldset>' +
                    '</div>');

                config_mitigation_div = view.add_mitigation_config_entries(config_mitigation_div, disabled);

                $(".bind_mitigation_level", config_mitigation_div).bind("change", function () {
                    controller.new_mitigation_levels[this.id]["text"] = this.value;
                    controller.mitigation_levels_to_change.push(controller.new_mitigation_levels[this.id]);
                    //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                })//bind_change
                var add_mitigation_level_div_id = config_mitigation_div_id + '_add';

                $('#add_level', config_mitigation_div).click(function () {
                    if (disabled == "") {
                        view.last_mitigation_level_used++;
                        view.last_mitigation_id++;
                        //add_impact_level = $('#add_level', config_impacts_div);
                        //$('.add_impact_level_container', config_impacts_div).remove('#add_level');
                        var last_entry = $('.bind_create_mitigation_level', config_mitigation_div);
                        last_entry.removeClass('.bind_create_mitigation_level');
                        last_entry.addClass('bind_mitigation_level');
                        var remove_id = "remove_" + generate_id();
                        var mitigation_div = $('<tr height="28px" id="' + view.last_mitigation_id + '" config_table_row>' +
                            '<td width="60px" style="text-align:center;">' +
                            view.last_mitigation_level_used +
                            '</td>' +
                            '<td width="120px" style="text-align:center;"><input class="bind_create_mitigation_level" type="text" id="' +
                            view.last_mitigation_id +
                            '"></td>' +
                            '<td width="26px" id="' +
                            remove_id +
                            '"><div class="remove_entry" ></div></td>' +
                            '</td>' +
                            '<tr>')

                        mitigation_div.hover(function () {
                                var remove_div = $('.remove_entry', this);
                                remove_div.removeClass("remove_entry");
                                remove_div.addClass("remove_entry_show");
                            }, //hover start
                            function () {
                                var remove_div = $('.remove_entry_show', this);
                                remove_div.removeClass("remove_entry_show");
                                remove_div.addClass("remove_entry");
                            }//hover end
                        )//hover
                        $('.bind_create_mitigation_level', mitigation_div).bind("change", function () {
                            var old_last = $('.bind_create_mitigation_level', mitigation_div);
                            old_last.removeClass('bind_create_mitigation_level');
                            old_last.addClass('bind_mitigation_level');

                            old_last.unbind("change").bind("change", function () {
                                controller.new_mitigation_levels[this.id].text = this.value;
                                //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                            })//existing entry changed
                            var mitigation_level = {
                                "value":++this.id,
                                "text":this.value,
                                "id":generate_id()
                            }//impact_level
                            controller.new_mitigation_levels[this.id - 1] = mitigation_level;
                            //controller.create_impact_level(impact_level);
                            controller.mitigation_levels_to_create.push(mitigation_level);
                            //alert("impact level " + controller.impact_levels[this.id].value + " " + controller.impact_levels[this.id].text);
                        })//new_entry changed
                        $('#mitigation_table', config_mitigation_div).append(mitigation_div);
                    }
                });//add_impact_level.click
                //configuration_div.append(config_impacts_div);
                $('#mitigation_level_configuration', configuration_div).append(config_mitigation_div);

                //**********************************************************************************************
                //                    Reidual Risk Status Level Configuration
                //**********************************************************************************************
                var config_residual_div_id = config_div_id + '_residual';
                var config_residual_div = $('<div class="config_residual_div">' +
                    '<fieldset id="' +
                    config_residual_div_id +
                    '" class="config_container">' +
                    '<legend>Residual Risk Status Level</legend>' +
                    '<div>' +
                    '<table width="240px" id="residual_table">' +
                    '<tr">' +
                    '<th width="60px" style="text-align:center;">Level</th>' +
                    '<th width="120px" style="text-align:center;">Residual Risk Status Level Text</th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '<table width="240px">' +
                    '<tr">' +
                    '<th width="60px">&nbsp;</th>' +
                    '<th width="120px"><div id="add_level" ' +
                    disabled +
                    ' class="grc_link">Add Residual Risk Status Level</div></th>' +
                    '<td width="26px">&nbsp;</td>' +
                    '</tr>' +
                    '</table>' +
                    '</fieldset>' +
                    '</div>');

                config_residual_div = view.add_residual_config_entries(config_residual_div, disabled);

                $(".bind_residual_level", config_residual_div).bind("change", function () {
                    controller.new_residual_levels[this.id]["text"] = this.value;
                    controller.residual_levels_to_change.push(controller.new_residual_levels[this.id]);
                    //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                })//bind_change
                var add_residual_level_div_id = config_residual_div_id + '_add';


                $('#add_level', config_residual_div).click(function () {
                    if (disabled == "") {
                        view.last_residual_level_used++;
                        view.last_residual_id++;
                        //add_impact_level = $('#add_level', config_impacts_div);
                        //$('.add_impact_level_container', config_impacts_div).remove('#add_level');
                        var last_entry = $('.bind_create_residual_level', config_residual_div);
                        last_entry.removeClass('.bind_create_residual_level');
                        last_entry.addClass('bind_residual_level');
                        var remove_id = "remove_" + generate_id();
                        var residual_div = $('<tr height="28px" id="' + view.last_residual_id + '" config_table_row>' +
                            '<td width="60px" style="text-align:center;">' +
                            view.last_residual_level_used +
                            '</td>' +
                            '<td width="120px" style="text-align:center;"><input class="bind_create_residual_level" type="text" id="' +
                            view.last_residual_id +
                            '"></td>' +
                            '<td width="26px" id="' +
                            remove_id +
                            '"><div class="remove_entry" ></div></td>' +
                            '</td>' +
                            '<tr>')

                        residual_div.hover(function () {
                                var remove_div = $('.remove_entry', this);
                                remove_div.removeClass("remove_entry");
                                remove_div.addClass("remove_entry_show");
                            }, //hover start
                            function () {
                                var remove_div = $('.remove_entry_show', this);
                                remove_div.removeClass("remove_entry_show");
                                remove_div.addClass("remove_entry");
                            }//hover end
                        )//hover
                        $('.bind_create_residual_level', residual_div).bind("change", function () {
                            var old_last = $('.bind_create_residual_level', residual_div);
                            old_last.removeClass('bind_create_residual_level');
                            old_last.addClass('bind_residual_level');

                            old_last.unbind("change").bind("change", function () {
                                controller.new_residual_levels[this.id].text = this.value;
                                //alert("changed to: " + controller.impact_levels[this.id]["text"]);
                            })//existing entry changed
                            var residual_level = {
                                "value":++this.id,
                                "text":this.value,
                                "id":generate_id()
                            }//impact_level
                            controller.new_residual_levels[this.id - 1] = residual_level;
                            //controller.create_impact_level(impact_level);
                            controller.residual_levels_to_create.push(residual_level);
                            //alert("impact level " + controller.impact_levels[this.id].value + " " + controller.impact_levels[this.id].text);
                        })//new_entry changed
                        $('#residual_table', config_residual_div).append(residual_div);
                    }
                });//add_impact_level.click

                //configuration_div.append(config_impacts_div);
                $('#residual_level_configuration', configuration_div).append(config_residual_div);

                //**********************************************************************************************
                //                    Aggregation Method Configuration
                //**********************************************************************************************
                var config_aggreg_div_id = config_div_id + '_aggreg';
                var select_aggreg_method_id = config_div_id + '_select_aggreg';
                var aggregation_div = $('<br><div>' +
                    '<fieldset id="' +
                    config_aggreg_div_id +
                    '" class="config_container">' +
                    '<legend>Aggregation Method</legend>' +
                    '<select id="' +
                    select_aggreg_method_id +
                    '" ' +
                    disabled +
                    ' class="option_input_dialog_aggreg">' +
                    '</select>' +
                    '</fieldset>' +
                    '</div>');
                var select_div = $('#' + select_aggreg_method_id, aggregation_div);
                for (var i = 0; i < controller.aggregation_methods.length; i++) {
                    select_div.append('<option value="' + controller.aggregation_methods[i] + '">' + controller.aggregation_methods[i] + '</option>');
                }
                ;//all aggregation methods
                $('#aggregation_method_configuration', configuration_div).append(aggregation_div);

                if (controller.selected_aggreg_method) {
                    $('#' + select_aggreg_method_id, aggregation_div).attr("value", controller.selected_aggreg_method);
                }
                ;

                $('#' + select_aggreg_method_id, aggregation_div).change(function () {
                    controller.update_selected_aggregation_method($('#' + select_aggreg_method_id + ' :selected', aggregation_div).val());
                });

                lipstick.showMethodDialog(configuration_div, {
                    title:'Properties',
                    ok:function () {
                        controller.commit_impact_levels();
                        controller.commit_probability_levels();
                        controller.commit_mitigation_levels();
                        controller.commit_residual_levels();
                        controller.set_config_unlocked();
                    },
                    cancel:function () {
                        controller.set_config_unlocked();
                        controller.new_probability_levels = controller.clone(controller.probability_levels);
                        controller.new_impact_levels = controller.clone(controller.impact_levels);
                        controller.new_mitigation_levels = controller.clone(controller.mitigation_effectiveness_levels);
                        controller.new_residual_levels = controller.clone(controller.residual_risk_levels);
                    },
                    width:600
                }/*, {
                 position: [150, null]
                 }*/);
            }, //show_configuration
            //--------------------------------------------------- SHOW CSV EXPORT----------------------------------------------
            //
            //---------------------------------------------------------------------------------------------------------------------
            show_csv_export:function () {
                var data = "";
                var final_data = "";
                var date = new Date
                var day = date.getUTCDate();
                var month = date.getUTCMonth() - (-1);
                var year = date.getUTCFullYear();
                var curren_date = day + "." + month + "." + year;
                for (var i = 0; i < controller.risks.length; i++) {
                    data = data + controller.risks[i].name + ",SAP_ORG_UNIT_ID,SAP_OBJECTIVE_ID,SAP_ACTIVITY_ID,SAP_RISK_CATEGORY_ID," + controller.risks[i].description + "," +
                        curren_date +
                        ",31.12.9999";
                    var risk_array = [];
                    for (var j in controller.risks[i].impacts) {
                        risk_array.push(controller.risks[i].impacts[j]);
                    }
                    for (var j = 0; j < risk_array.length; j++) {
                        data = data + ",SAP_IMPACT_CAT_" + risk_array[j].category + "," + risk_array[j].name;
                    }
                    data = data + ",,,,,,,,,,,,\n";
                    final_data = final_data + data;
                    data = "";
                }


                lipstick.alert("TO upload the Risks to SAP RM please change the IDs to the RM IDs manually.");
                //window.location='data:text/csv;charset=utf8,' + encodeURIComponent(final_data);
                window.location = 'data:application/csv;charset=utf8,' + encodeURIComponent(final_data);
                return true;


            }, //show_csv_export
            //--------------------------------------------------- HIDE NEW ASSESSMENT----------------------------------------------
            //
            //---------------------------------------------------------------------------------------------------------------------
            hide_new_assessment:function (collapse_id, arrow_id, update, assessment_name_id) {
                var collapse_div = $('#' + collapse_id);
                collapse_div.hide();
                $('#' + arrow_id).unbind('click').click(function () {
                    view.show_new_assessment(collapse_id, arrow_id, assessment_name_id);
                });//arrow_clicked
                var image = $('#' + arrow_id);
                image.attr("src", "http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/open.png");
                if (update == true) {
                    controller.update_assessment_container(collapse_id, false, arrow_id);
                }
            }, //hide_new_assessment
            //--------------------------------------------------- SHOW ASSESSMENT ----------------------------------------------
            //
            //---------------------------------------------------------------------------------------------------------------------
            show_new_assessment:function (collapse_id, arrow_id, assessment_name_id) {
                $('#' + collapse_id).show();
                $('#' + arrow_id).unbind('click').click(function () {
                    view.hide_new_assessment(collapse_id, arrow_id, true, assessment_name_id);
                });//arrow_clicked
                $($("#" + assessment_name_id)[0]).click(function () {
                    var assessmentName = $("#" + assessment_name_id);
                    assessmentName.removeClass('title_editable');
                    if ($(this).val() === "New Assessment") {
                        $(this).val('');
                    }
                });//AssessmentName.click
                var image = $('#' + arrow_id);
                image.attr("src", "http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/close.png");
                controller.update_assessment_container(collapse_id, true, arrow_id);
            }, //show_assessment
            //--------------------------------------------------- CREATED RISK ----------------------------------------------------
            //       displaying a new created risk in the risk list within the main view
            //---------------------------------------------------------------------------------------------------------------------
            show_created_risk:function (risk) {
                var placeholder_div = $('#placeholder_new_risks');
                var remove_id = risk.id + "_remove";
                var edit_id = risk.id + "_edit"; //added by D053422
                new_risk_div_string = //'<div id="' +  risk.id + '" class="risk_table_entry">' +
                    '<div id="' + risk.id + '">' +
                        //'<div class="table_left"></div>'+
                        '<div class="table_middle2 resizable_body2" style="min-height:32px;">' +
                        '<table width="100%" style="margin:10px;text-align:center;">' +
                        '<td width="15%">' +
                        risk.name +
                        '</td>' +
                        '<td width="20%">' +
                        risk.description +
                        '</td>' +
                        '<td width="20%">' +
                        risk.category +
                        '</td>' +
                        '<td width="20%">' +
                        risk.org_unit +
                        '</td>' +
                        '<td width="20%">';
                if (risk.impacts) {
                    new_risk_div_string = new_risk_div_string + '<table width="100%" id="' + risk.id + 'impacts' + '">';
                    //firefox fix for impacts sequence
                    try {
                        //for (i in risk.impacts) {
                        for (i = 0; ; i++) {
                            new_risk_div_string = new_risk_div_string + '<tr style="text-align:center;"><td width="50%">' + risk.impacts[i].name + '</td><td width="50%">' + risk.impacts[i].category + '</td></tr>';
                        }
                    } catch (e) {
                    }
                    new_risk_div_string = new_risk_div_string + '</table>';
                }
                new_risk_div_string = new_risk_div_string + '</td><td width="16px" height="16px"></div><div id="' + edit_id + '" class="edit_entry"></div><div id="' + remove_id + '" class="remove_entry"></td>' +
                    '</table></div>' +
                    '</div>';
                var new_risk_div = $(new_risk_div_string);

                //$('#' + remove_id, new_risk_div).click(function(){
                $('.remove_entry', new_risk_div).click(function () {
                    var table_entry = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
                    var warning_text = 'Do you really want to delete this Risk? You can not use the Risk in new Assessments any more.', warning_string = '<div class="grc_warning_body"><div class="grc_warning_icon_container"><div class="grc_warning_icon"/></div>' +
                        '<div class="grc_warning_message_container"><div class="grc_warning_content_div"></div>' +
                        warning_text +
                        '<div class="grc_warning_content_div"></div></div></div>', warning = $(warning_string), options = {
                        onOK:function () {
                            $(table_entry).hide();
                            for (var i = 0; i < controller.risks.length; i++) {
                                if (controller.risks[i].id == table_entry.id) {
                                    controller.risks[i].deleted = true;
                                    controller.update_risk(controller.risks[i]);
                                    break;
                                }
                            }//search for deleted risk
                        }, //onOK
                        title:"Delete Risk",
                        okLabel:"OK",
                        cancelLabel:"Cancel"
                    }
                    lipstick.dialog(warning, options);

                })//on remove
                //ADDITIONAL CODING BY D053422
                $('.edit_entry', new_risk_div).click(function () {
                    //determine risk
                    var table_entry = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
                    var aRisk;
                    for (var i = 0; i < controller.risks.length; i++) {
                        if (controller.risks[i].id == table_entry.id) {
                            aRisk = controller.risks[i];
                            break;
                        }
                    }
                    view.show_edit_risk(aRisk);

                })//on edit
                //END OF ADDITIONAL CODING2
                /*
                 Commented out by C5163319
                 new_risk_div.hover(function() {
                 var remove_div = $('.remove_entry', this);
                 remove_div.removeClass("remove_entry");
                 remove_div.addClass("remove_entry_show");
                 //ADDITIONAL CODING BY D053422
                 var edit_div = $('.edit_entry', this);
                 edit_div.removeClass("edit_entry");
                 edit_div.addClass("edit_entry_show");
                 }, //hover start
                 function() {
                 var remove_div = $('.remove_entry_show', this);
                 remove_div.removeClass("remove_entry_show");
                 remove_div.addClass("remove_entry");
                 //ADDITIONAL CODING BY D053422
                 var edit_div = $('.edit_entry_show', this);
                 edit_div.removeClass("edit_entry_show");
                 edit_div.addClass("edit_entry");
                 }//hover end
                 );//hover

                 end commented out by C5163319
                 */
                placeholder_div.append(new_risk_div);


                //var impact_table_div = $('#' + risk.id + 'impacts');
                /*for (i in risk.impacts) {
                 var impact_div_string = '<tr style="text-align:center;"><td width="50%">' + risk.impacts[i].name + '</td><td width="50%">' + risk.impacts[i].category + '</td></tr>';
                 //$('#' + risk.id).height($('#' + risk.id).height() + 10);
                 new_risk_div.height($('#' + risk.id).height() + 10);
                 impact_table_div.append(impact_div_string);
                 }*/
                view._viewResizeHandler();

            }, //show_created_risk
            //--------------------------------------------------- ADDED IMPACT ----------------------------------------------------
            //       displaying the added impac
            //---------------------------------------------------------------------------------------------------------------------
            show_added_impact:function (name, category) {
                var placeholder_div = $('#placeholder_new_impact');
                new_impact_string = '<div class="impact">' +
                    '<table width="100%">' +
                    '<td width="40%">' +
                    name +
                    '</td>' +
                    '<td width="50%">' +
                    category +
                    '</td>' +
                    '</table>' +
                    '</div>';
                placeholder_div.append(new_impact_string);

                /*
                 var table = $('#' + table_id);
                 var new_impact_string =
                 '<tr>' +
                 '<td>' +
                 '<input class="mini_input_dialog" type="text" value="' + name + '" id="' + name_id +'"/>' +
                 '</td>' +
                 '<td>' +
                 '<input class="mini_input_dialog" type="text" value="' + value.category + '" id="' + cat_id + '"/>' +
                 '</td>' +
                 '</tr>';
                 */
            }, //show_added_impact
            //------------------------------------------------- ADD ASSIGNED RISK --------------------------------------------------
            //
            //---------------------------------------------------------------------------------------------------------------------
            add_assigned_risk:function (placeholder_id, risk_id) {
                var remove_id = "remove_" + generate_id();
                var table_id = risk_id + "_assessment_entry";
                for (var i = 0; i < controller.risks.length; i++) {
                    var risk = controller.risks[i];
                    if (risk.id == risk_id) {
                        assigned_risk_div_string = ('<table width="100%" style="min-height:30px;margin-top:10px;">' +
                            '<tr id="' +
                            table_id +
                            '" width="100%" style="min-height:30px;">' +
                            '<td width="24%">' +
                            risk.name +
                            '</td>' +
                            '<td width="24%">' +
                            risk.description +
                            '</td>' +
                            '<td width="24%">' +
                            risk.category +
                            '</td>' +
                            '<td width="24%">' +
                            risk.org_unit +
                            '</td>' +
                            '<td width="16px" height="16px" id="' +
                            remove_id +
                            '"><div class="remove_entry" ></div></td>' +
                            '</tr>' +
                            '</table>');
                        var assigned_risk_div = $(assigned_risk_div_string);
                        $('#' + remove_id, assigned_risk_div).click(function () {
                            var risk_id = this.parentNode.id;
                            risk_id = risk_id.substring(0, risk_id.indexOf("_"));
                            var assessment_id = placeholder_id;
                            var index = assessment_id.indexOf("_");
                            index = assessment_id.indexOf("_", index + 1);
                            index = assessment_id.indexOf("_", index + 1);
                            index = assessment_id.indexOf("_", index + 1);
                            index = assessment_id.indexOf("_", index + 1);
                            index = assessment_id.indexOf("_", index + 1);
                            var assessment_id = assessment_id.substring(index + 1);
                            var deleted = false;
                            var updated_risks = {};
                            for (var i = 0; i < controller.assessments.length; i++) {
                                if (controller.assessments[i].id == assessment_id) {
                                    var assessment = controller.assessments[i];
                                    for (var j in assessment.risks) {
                                        if (deleted == false) {
                                            if (assessment.risks[j] == risk_id) {
                                                deleted = true;
                                                continue;
                                            }//if risk to deleteel
                                            updated_risks[j] = assessment.risks[j];
                                        }//if deleted
                                        updated_risks[j - 1] = assessment.risks[j];
                                    }//for risks
                                    controller.assessments[i].risks = updated_risks;
                                    controller.update_assessment(controller.assessments[i]);
                                }//if
                            }//for assessments
                            $(this.parentNode.parentNode.parentNode).hide();
                        })//on remove
                        /*
                         $('#' + table_id, assigned_risk_div).hover(function() {
                         var remove_div = $('.remove_entry', this);
                         remove_div.removeClass("remove_entry");
                         remove_div.addClass("remove_entry_show");
                         }, //hover start
                         function() {
                         var remove_div = $('.remove_entry_show', this);
                         remove_div.removeClass("remove_entry_show");
                         remove_div.addClass("remove_entry");
                         }//hover end
                         )//hover
                         */
                        $('#' + placeholder_id).append(assigned_risk_div);
                        break;
                    }//if
                }//for
            }, //add_assigned_risk
            //---------------------------------------------------- NEW RISK -------------------------------------------------------
            //       handeling the popup for the creation of a new risk
            //---------------------------------------------------------------------------------------------------------------------
            new_risk_div_id:elementId + '_new_risk',

            test:function () {
                //alert("test");
            },

            show_new_risk:function () {

                var risk = {
                    id:generate_id(),
                    name:"",
                    category:"",
                    category_id:"",
                    description:"",
                    org_unit:"",
                    org_unit_id:"",
                    impacts:[],
                    rm_assessment_id:"",
                    deleted:false
                }
                var new_risk_div = $('<div>' +
                    '<div class="new_dialog_title">Name&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div class="name_input_holder"><input class="default_input_field" type="text" id="name" value="Name"/></div>' +
                    '<div class="new_dialog_title">Description&nbsp;<span class="dialog_optional">(Optional)</span></div>' +
                    '<div class="name_input_holder"><input class="default_input_field" type="text" id="description" value="Description"/></div>' +
                    '<div class="new_dialog_title">Category&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div id="div_select_category" class="name_input_holder">' +
                    '<select id="select_category" class="option_input_dialog">' +
                    '</select>' +
                    '</div>' +
                    '<div class="name_input_holder" id="div_new_category_input" style="display:none; position:relative;">' +
                    '<input class="text_input_dialog" type="text" id="new_category_input" style="width:90% !important;"/>' +
                    '<img id="ok_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                    '<img id="cancel_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                    '</div>' +
                    '<div class="new_dialog_title">Organization Unit&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div id="div_select_org_unit" class="name_input_holder">' +
                    '<select id="select_org_unit" class="option_input_dialog">' +
                    '</select>' +
                    '</div>' +
                    '<div class="name_input_holder" id="div_new_org_unit_input" style="display:none; position:relative;">' +
                    '<input class="text_input_dialog" type="text" id="new_org_unit_input" style="width:90% !important;"/>' +
                    '<img id="ok_org_unit" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                    '<img id="cancel_org_unit" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                    '</div>' +
                    '<div>' +
                    '<div class="risk_impacts_table_head">Impacts&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div">' +
                    '<table width="100%">' +
                    '<th width="40%">Name</th>' +
                    '<th width="50%">Category</th>' +
                    //'<th width="10%"></th>'+
                    '</table>' +
                    '</div>' +
                    '<div id="placeholder_new_impact"></div>' +
                    '</div>' +
                    '<div>' +
                    '<table width="100%">' +
                    '<td width="40%">' +
                    '<div class="name_input_holder">' +
                    '<input type="text" id="impact_name" class="text_input_dialog">' +
                    '</div>' +
                    '</td>' +
                    '<td width="50%">' +
                    '<div id="div_select_impact_category" class="name_input_holder">' +
                    '<select id="select_impact_category" class="option_input_dialog">' +
                    '</select>' +
                    '</div>' +
                    '<div class="name_input_holder" id="div_new_impact_category_input" style="display:none;">' +
                    '<input class="text_input_dialog" type="text" id="new_impact_category_input" style="width:80% !important;"/>' +
                    '<img id="ok_impact_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                    '<img id="cancel_impact_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                    '</div>' +
                    '</td>' +
                    //'<td>'+
                    //    '<div class="ok_holder">'+
                    //    '<img id="add_impact" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/add.png">'+
                    //    '</div>'+
                    '</td>' +
                    '</table>' +
                    '<div id="add_impact" class="grc_link">Add Impact</div>' +
                    '</div>').attr('id', view.new_risk_div_id)

                view.loading_target = new_risk_div;

                $('#name', new_risk_div).focus(function () {
                    var name = $('#name', new_risk_div);
                    name.attr("value", "");
                    name.removeClass("default_input_field");
                    name.addClass("text_input_dialog");
                }), $('#description', new_risk_div).focus(function () {
                    var description = $('#description', new_risk_div);
                    description.attr("value", "");
                    description.removeClass("default_input_field");
                    description.addClass("text_input_dialog");
                }), $('#add_impact', new_risk_div).click(function () {
                    var impact_category = $('#select_impact_category :selected').val(), impact_category_text = $('#select_impact_category :selected').text(), impact_category_val = $('#select_impact_category :selected').val(), impact_name = $('#impact_name').val();

                    if (impact_name == "" || impact_category == 0) {
                        lipstick.alert("Please enter both a name and choose a category for the impact.", "impact_name_missing", "Impact value missing");
                        $('#impact_name', new_risk_div).focus();
                    }
                    else {
                        var id = generate_id();
                        risk.impacts.push({
                            name:impact_name,
                            category:impact_category_text,
                            category_id:impact_category_val
                        });
                        //view.impacts.push({ name : impact_name, category : impact_category });
                        view.show_added_impact(impact_name, impact_category_text);
                        $('#impact_name').attr('value', "");
                        $('#select_impact_category').attr('value', 0);
                    }
                    risk.category = $("#select_category :selected", new_risk_div).text();
                    risk.org_unit = $("#select_org_unit :selected", new_risk_div).text();
                    risk.category_id = $("#select_category :selected", new_risk_div).val();
                    risk.org_unit_id = $("#select_org_unit :selected", new_risk_div).val();
                }), $('#ok_impact_category', new_risk_div).click(function () {
                    controller.create_impact_category();
                });

                $('#new_impact_category_input', new_risk_div).keyup(function (e) {
                    if (e.keyCode == 13) {
                        controller.create_impact_category();
                    }
                });//enter in impact name
                $('#new_impact_category_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_impact_category_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#cancel_impact_category', new_risk_div).click(function () {
                    $('#div_new_impact_category_input', new_risk_div).css('display', 'none');
                    $('#div_select_impact_category', new_risk_div).css('display', 'block');
                    $('#select_impact_category', new_risk_div).attr('value', 0);
                });

                $('#ok_category', new_risk_div).click(function () {
                    controller.create_risk_category();
                });

                $('#new_category_input', new_risk_div).keyup(function (evt) {
                    if (evt.keyCode == 13) {
                        controller.create_risk_category();
                    }
                });//enter in category
                $('#cancel_category', new_risk_div).click(function () {
                    $('#div_new_category_input', new_risk_div).css('display', 'none');
                    $('#div_select_category', new_risk_div).css('display', 'block');
                    //$('#select_category', new_risk_div).attr('value', 0);
                });

                $('#new_category_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_category_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#ok_org_unit', new_risk_div).click(function () {
                    controller.create_org_unit();
                });

                $('#new_org_unit_input', new_risk_div).keyup(function (evt) {
                    if (evt.keyCode == 13) {
                        controller.create_org_unit();
                    }
                });//enter in category
                $('#new_org_unit_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_org_unit_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#cancel_org_unit', new_risk_div).click(function () {
                    $('#div_new_org_unit_input', new_risk_div).css('display', 'none');
                    $('#div_select_org_unit', new_risk_div).css('display', 'block');
                    $('#select_org_unit', new_risk_div).attr('value', 0);
                });

                //TODO
                if (controller.host != null) {
                    if ((controller.host != null) && (controller.risk_categories == null)) {
                        //controller.get_customizing();
                    }
                    //append risk categories from SAP system to select option
                    var select_category = $('#select_category', new_risk_div);
                    var risk_categories = controller.risk_categories;
                    select_category.append('<option value="0" id="empty_category"></option>');
                    for (var i = 0; i < risk_categories.length; i++) {
                        var category = risk_categories[i];
                        select_category.append('<option id="' + category.id + '" value="' + category.id + '">' + category.text + '</option>');
                    }//for
                    //append risk categories from SAP system to select option
                    var select_org_unit = $('#select_org_unit', new_risk_div);
                    var org_units = controller.org_units;
                    select_org_unit.append('<option value="0" id="empty_org"></option>');
                    for (var i = 0; i < org_units.length; i++) {
                        var org_unit = org_units[i];
                        select_org_unit.append('<option id="' + org_unit.id + '" value="' + org_unit.id + '">' + org_unit.text + '</option>');
                    }//for
                    //append risk categories from SAP system to select option
                    var select_impact_categories = $('#select_impact_category', new_risk_div);
                    var impact_categories = controller.impact_categories;
                    select_impact_categories.append('<option value="0" id="empty_org"></option>');
                    for (var i = 0; i < impact_categories.length; i++) {
                        var impact_category = impact_categories[i];
                        if (impact_category.id) {
                            select_impact_categories.append('<option id="' + impact_category.id + '" value="' + impact_category.id + '">' + impact_category.text + '</option>');
                        }
                    }//for

                }
                else {
                    proxy.get_impact_categories();
                    proxy.get_risk_categories();
                    proxy.get_org_units();
                }


                lipstick.showMethodDialog(new_risk_div, {
                    title:'New Risk',
                    ok:function () {
                        //edited 23.12.2011
                        lipstick.addWaitOverlay(new_risk_div);

                        //TODO: wait for response changing those fields
                        if ($("#div_new_category_input").is(":visible")) {
                            $("#ok_category", new_risk_div).click();
                        }

                        if ($("#div_new_org_unit_input").is(":visible")) {
                            $("#ok_org_unit", new_risk_div).is(":visible");
                        }

                        if ($("#impact_name", new_risk_div).val() != '') {
                            if ($("#div_select_impact_category", new_risk_div).is(":visible")) {
                                if ($("#new_impact_category_input", new_risk_div).val() != '0') {
                                    $("#add_impact", new_risk_div).click();
                                }
                            } else if ($("#div_new_impact_category_input", new_risk_div).is(":visible")) {
                                if ($("#new_impact_category_input", new_risk_div).val() != '' && $("#new_impact_category_input", new_risk_div).val() != "New Impact Category") {
                                    $("#add_impact", new_risk_div).click();
                                }
                            }
                        }

                        if ($('#name', new_risk_div).val() != "Name") {
                            risk.name = $('#name', new_risk_div).val();
                        } else {
                            risk.name = '';
                        }

                        if ($('#description', new_risk_div).val() != "Description") {
                            risk.description = $('#description', new_risk_div).val();
                        }

                        if ($("#select_category :selected", new_risk_div).text() != "New Risk Category") {
                            risk.category = $("#select_category :selected", new_risk_div).text();
                        } else {
                            risk.category = "";
                        }

                        if ($("#select_org_unit :selected", new_risk_div).text()) {
                            risk.org_unit = $("#select_org_unit :selected", new_risk_div).text();
                        } else {
                            risk.org_unit = "";
                        }

                        risk.category_id = $("#select_category :selected", new_risk_div).val();
                        risk.org_unit_id = $("#select_org_unit :selected", new_risk_div).val();

                        if ((risk.name != "") && (risk.category != "") && (risk.org_unit != "") && (risk.impacts.length > 0)) {
                            controller.create_risk(risk);
                            lipstick.removeWaitOverlay(new_risk_div);
                        } else {
                            lipstick.alert("Please fill all required fields.", "impact_name_missing", "Risk information missing");
                            lipstick.removeWaitOverlay(new_risk_div);
                            return false;
                        }

                    },

                    okLabel:'Create',
                    width:374
                }, {
                    //position: [150, null]
                });
                //alert("new risk clicked");
            }, //show_new_risk

            //-------------------------------------------------- EDIT RISK --------------------------------------------------------
            //  added by D053422
            //---------------------------------------------------------------------------------------------------------------------
            show_edit_risk:function (iRisk) {

                /*var updatedRisk = {
                 id: iRisk.id,
                 name: "",
                 category: "",
                 category_id : "",
                 description: "",
                 org_unit: "",
                 org_unit_id : "",
                 impacts: [],
                 rm_assessment_id: "",
                 deleted: false
                 }*/
                var updatedRisk = jQuery.extend(true, {}, iRisk);

                //add existing impacts
                var index = 0;
                var anImpact = iRisk.impacts[index];
                var impactString = '';
                var placeholder_div = $('#placeholder_new_impact');
                var impactsArray = [];

                //changed by C5163319
                var impact_table_id = "impact_edit_table_" + elementId;
                var impactString =
                    '<table class="impact_edit_table" width="100%" id="' + impact_table_id + '">' +
                        '<tr>' +
                        '<th width="40%">Impact Name</th>' +
                        '<th width="50%">Impact Category</th>' +
                        '</tr>';

                var impactsArray = [];
                var impact_table_input_ids = [];
                $.each(iRisk.impacts, function (index, value) {
                    var name_id = impact_table_id + '_name' + index;
                    var cat_id = impact_table_id + '_cat' + index;

                    impact_table_input_ids.push({
                        index:index,
                        name:name_id,
                        category:cat_id
                    });

                    var new_impact_string =
                        '<tr>' +
                            '<td width="40%" class="name_input_holder">' +
                            '<input class="text_input_dialog" type="text" value="' + value.name + '" id="' + name_id + '"/>' +
                            '</td>' +
                            '<td width="50%" class="name_input_holder">' +
                            '<select id="' + cat_id + '" class="option_input_dialog">' +
                            '<option value="' + value.category + '" selected="selected">' + value.category + '</option>' +
                            '</select>' +
                            '</td>' +
                            '</tr>';
                    //alert(new_impact_string);
                    impactsArray.push(value);
                    impactString = impactString + new_impact_string;
                });

                controller.impact_table_input_ids = impact_table_input_ids;

                impactString = impactString + '</table>';

                updatedRisk.impacts = impactsArray;

                var new_risk_div = $(
                    '<div>' +
                        '<div class="new_dialog_title">Name&nbsp;' +
                        '<span class="dialog_required">(Required)</span>' +
                        '</div>' +
                        '<div class="name_input_holder">' +
                        '<input class="text_input_dialog" type="text" id="name" value="' + iRisk.name + '"/>' +
                        '</div>' +
                        '<div class="new_dialog_title">Description&nbsp;' +
                        '<span class="dialog_optional">(Optional)</span>' +
                        '</div>' +
                        '<div class="name_input_holder">' +
                        '<input class="text_input_dialog" type="text" id="description" value="' + iRisk.description + '"/>' +
                        '</div>' +
                        '<div class="new_dialog_title">Category&nbsp;' +
                        '<span class="dialog_required">(Required)</span>' +
                        '</div>' +
                        '<div id="div_select_category" class="name_input_holder">' +
                        '<select id="select_category" class="option_input_dialog"></select>' +
                        '</div>' +
                        '<div class="name_input_holder" id="div_new_category_input" style="display:none; position:relative;">' +
                        '<input class="text_input_dialog" type="text" id="new_category_input" style="width:90% !important;"/>' +
                        '<img id="ok_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                        '<img id="cancel_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                        '</div>' +
                        '<div class="new_dialog_title">Organization Unit&nbsp;' +
                        '<span class="dialog_required">(Required)</span>' +
                        '</div>' +
                        '<div id="div_select_org_unit" class="name_input_holder">' +
                        '<select id="select_org_unit" class="option_input_dialog"></select>' +
                        '</div>' +
                        '<div class="name_input_holder" id="div_new_org_unit_input" style="display:none; position:relative;">' +
                        '<input class="text_input_dialog" type="text" id="new_org_unit_input" style="width:90% !important;"/>' +
                        '<img id="ok_org_unit" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                        '<img id="cancel_org_unit" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                        '</div>' +
                        '<div>' +
                        '<div class="risk_impacts_table_head">Impacts<span class="dialog_required">(Required)</span></div>' +
                        //'<div">' +
                        //'<table width="100%">' +
                        //'<th width="40%">Name</th>' +
                        //'<th width="50%">Category</th>' +
                        //'<th width="10%"></th>'+
                        //'</table>' +
                        '</div>' +
                        impactString +
                        '<div id="placeholder_new_impact"></div>' +
                        //'</div>' +
                        '<div>' +
                        '<table width="100%">' +
                        '<td width="40%">' +
                        '<div class="name_input_holder">' +
                        '<input type="text" id="impact_name" class="text_input_dialog">' +
                        '</div>' +
                        '</td>' +
                        '<td width="50%">' +
                        '<div id="div_select_impact_category" class="name_input_holder">' +
                        '<select id="select_impact_category" class="option_input_dialog"></select>' +
                        '</div>' +
                        '<div class="name_input_holder" id="div_new_impact_category_input" style="display:none;">' +
                        '<input class="text_input_dialog" type="text" id="new_impact_category_input" style="width:80% !important;"/>' +
                        '<img id="ok_impact_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/ok.png">' +
                        '<img id="cancel_impact_category" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/cancel.png">' +
                        '</div>' +
                        '</td>' +
                        //'<td>'+
                        //    '<div class="ok_holder">'+
                        //    '<img id="add_impact" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/add.png">'+
                        //    '</div>'+
                        '</td>' +
                        '</table>' +
                        '<div id="add_impact" class="grc_link">Add Impact</div>' +
                        '</div>').attr('id', view.new_risk_div_id);

                view.loading_target = new_risk_div;

                $('#add_impact', new_risk_div).click(function () {
                    //23.12.2011 from here
                    var impact_category = '';
                    var impact_category_text = '';

                    if ($("#div_select_impact_category", new_risk_div).is(":visible")) {
                        if ($("#new_impact_category_input", new_risk_div).val() != '0') {
                            impact_category = $('#select_impact_category :selected').val();
                            impact_category_text = $('#select_impact_category :selected').text();

                        }
                    } else if ($("#div_new_impact_category_input", new_risk_div).is(":visible")) {
                        if ($("#new_impact_category_input", new_risk_div).val() != '' && $("#new_impact_category_input", new_risk_div).val() != "New Impact Category") {
                            impact_category_text = $("#new_impact_category_input", new_risk_div).val();
                            impact_category = '1';
                        }
                    }

                    /*var impact_category = $('#select_impact_category :selected').val();
                     var impact_category_text = $('#select_impact_category :selected').text();
                     //var impact_category_val = $('#select_impact_category :selected').val();*/
                    //to here
                    if (impact_name == "" || impact_category == 0) {
                        lipstick.alert("Please select an impact type and type in a impact name.",
                            "impact_name_missing",
                            "Impact value missing");
                        $('#impact_name', new_risk_div).focus();
                    }
                    else {

                        updatedRisk.impacts.push({
                            name:impact_name,
                            category:impact_category_text,
                            category_id:impact_category
                        });
                        //view.impacts.push({ name : impact_name, category : impact_category });
                        view.show_added_impact(impact_name, impact_category_text);
                        $('#impact_name').attr('value', "");
                        $('#select_impact_category').attr('value', 0);

                    }
                }), $('#ok_impact_category', new_risk_div).click(function () {
                    controller.create_impact_category();
                });

                $('#new_impact_category_input', new_risk_div).keyup(function (e) {
                    if (e.keyCode == 13) {
                        controller.create_impact_category();
                    }
                });//enter in impact name
                $('#new_impact_category_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_impact_category_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#cancel_impact_category', new_risk_div).click(function () {
                    $('#div_new_impact_category_input', new_risk_div).css('display', 'none');
                    $('#div_select_impact_category', new_risk_div).css('display', 'block');
                    $('#select_impact_category', new_risk_div).attr('value', 0);
                });

                $('#ok_category', new_risk_div).click(function () {
                    controller.create_risk_category();
                });

                $('#new_category_input', new_risk_div).keyup(function (evt) {
                    if (evt.keyCode == 13) {
                        controller.create_risk_category();
                    }
                });//enter in category
                $('#cancel_category', new_risk_div).click(function () {
                    $('#div_new_category_input', new_risk_div).css('display', 'none');
                    $('#div_select_category', new_risk_div).css('display', 'block');
                    //$('#select_category', new_risk_div).attr('value', 0);
                });

                $('#new_category_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_category_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#ok_org_unit', new_risk_div).click(function () {
                    controller.create_org_unit();
                });

                $('#new_org_unit_input', new_risk_div).keyup(function (evt) {
                    if (evt.keyCode == 13) {
                        controller.create_org_unit();
                    }
                });//enter in category
                $('#new_org_unit_input', new_risk_div).focus(function () {
                    var input_filed = $('#new_org_unit_input', new_risk_div);
                    input_filed.removeClass("default_text");
                    input_filed.attr('value', "");
                });//focus category_input
                $('#cancel_org_unit', new_risk_div).click(function () {
                    $('#div_new_org_unit_input', new_risk_div).css('display', 'none');
                    $('#div_select_org_unit', new_risk_div).css('display', 'block');
                    $('#select_org_unit', new_risk_div).attr('value', 0);
                });

                //TODO
                if (controller.host != null) {
                    if ((controller.host != null) && (controller.risk_categories == null)) {
                        //controller.get_customizing();
                    }
                    //append risk categories from SAP system to select option
                    var select_category = $('#select_category', new_risk_div);
                    var risk_categories = controller.risk_categories;
                    select_category.append('<option value="0" id="empty_category"></option>');
                    for (var i = 0; i < risk_categories.length; i++) {
                        var category = risk_categories[i];
                        select_category.append('<option id="' + category.id + '" value="' + category.id + '">' + category.text + '</option>');
                    }//for
                    //append risk categories from SAP system to select option
                    var select_org_unit = $('#select_org_unit', new_risk_div);
                    var org_units = controller.org_units;
                    select_org_unit.append('<option value="0" id="empty_org"></option>');
                    for (var i = 0; i < org_units.length; i++) {
                        var org_unit = org_units[i];
                        select_org_unit.append('<option id="' + org_unit.id + '" value="' + org_unit.id + '">' + org_unit.text + '</option>');
                    }//for
                    //append risk categories from SAP system to select option
                    var select_impact_categories = $('#select_impact_category', new_risk_div);

                    var impact_categories = controller.impact_categories;
                    select_impact_categories.append('<option value="0" id="empty_org"></option>');
                    for (var i = 0; i < impact_categories.length; i++) {
                        var impact_category = impact_categories[i];
                        if (impact_category.id) {
                            select_impact_categories.append('<option id="' + impact_category.id + '" value="' + impact_category.id + '">' + impact_category.text + '</option>');
                        }
                    }//for


                }
                else {
                    proxy.get_impact_categories();
                    proxy.get_risk_categories();
                    proxy.get_org_units();
                }

                lipstick.showMethodDialog(new_risk_div, {
                    title:'Edit existing Risk',
                    ok:function () {
                        updatedRisk.name = $('#name', new_risk_div).val();
                        if ($('#description', new_risk_div).val() != "Description") {
                            updatedRisk.description = $('#description', new_risk_div).val();
                        }

                        //update impact names and categories here
                        for (var i = 0; i < impact_table_input_ids.length; i++) {
                            var name = $('#' + impact_table_input_ids[i].name, new_risk_div).val();
                            var category = $('#' + impact_table_input_ids[i].category, new_risk_div).val();

                            if (!updatedRisk.impacts[impact_table_input_ids[i].index])
                                updatedRisk.impacts[impact_table_input_ids[i].index] = { };
                            updatedRisk.impacts[impact_table_input_ids[i].index].name = name;
                            updatedRisk.impacts[impact_table_input_ids[i].index].category = category;
                        }
                        //alert(JSON.stringify(impacts, null, '    '));


                        updatedRisk.category = $("#select_category :selected", new_risk_div).text();
                        updatedRisk.org_unit = $("#select_org_unit :selected", new_risk_div).text();
                        updatedRisk.category_id = $("#select_category :selected", new_risk_div).val();
                        updatedRisk.org_unit_id = $("#select_org_unit :selected", new_risk_div).val();
                        //alert(JSON.stringify(updatedRisk.impacts, null, '    '));
                        if ((updatedRisk.name != "") && (updatedRisk.category != "") &&
                            (updatedRisk.org_unit != "") && (updatedRisk.impacts.length > 0)) {
                            //update risk
                            controller.update_risk(updatedRisk);
                            //refresh user interface
                            //$(view.div[0]).children.remove();
                            //view.show_main_view();
                            //controller.create_risk(risk);
                        }
                        else {
                            lipstick.alert("Please give a Name, a Category and a Organization Unit to create a new Risk.", "impact_name_missing", "Risk information missing");
                        }

                    },

                    okLabel:'Edit Risk',
                    width:374
                }, {
                    //position: [150, null]
                });

                controller.selected_org_unit_id = iRisk.org_unit_id;
                controller.selected_category_id = iRisk.category_id;

                //alert("new risk clicked");
            }, //show_edit_risk


            //-------------------------------------------------- NEW ORG UNIT -----------------------------------------------------
            //     handeling the popup for the creation of a new org unit
            //---------------------------------------------------------------------------------------------------------------------
            new_org_unit_div_id:elementId + '_new_org_unit',

            show_new_org_unit:function () {
                var new_org_unit_div = $('<div>' +
                    '<div class="new_dialog_title">Organization Unit&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div class="name_input_holder"><input class="text_input_dialog" type="text" id="org_unit" width="100%"/></div>' +
                    '</div>').attr('id', view.new_org_unit_div_id)

                lipstick.showMethodDialog(new_org_unit_div, {
                    title:'New Organization Unit',
                    ok:function () {
                        controller.create_org_unit();
                    },

                    okLabel:'Create',
                    width:430
                }, {
                    position:[150, null]
                });//lipstick.showMethodDialog
            }, //show_new_risk_category

            //------------------------------------------------- NEW RISK CATEGORY -------------------------------------------------
            //     handeling the popup for the creation of a new risk category
            //---------------------------------------------------------------------------------------------------------------------
            new_risk_category_div_id:elementId + '_new_risk_category',

            show_new_risk_category:function () {
                var new_risk_category_div = $('<div>' +
                    '<div class="new_dialog_title">Category&nbsp;<span class="dialog_required">(Required)</span></div>' +
                    '<div class="name_input_holder"><input class="text_input_dialog" type="text" id="category_name" width="100%"/></div>' +
                    '</div>').attr('id', view.new_risk_category_div_id)

                lipstick.showMethodDialog(new_risk_category_div, {
                    title:'New Risk Category',
                    ok:function () {
                        controller.create_risk_category();
                    },

                    okLabel:'Create',
                    width:430
                }, {
                    position:[150, null]
                });//lipstick.showMethodDialog
            }, //show_new_risk_category
            default_due_date:'Due Data',

            //------------------------------------------------ NEW RISK ASSESSMENT ------------------------------------------------
            //     creates the space for new Assessment
            //---------------------------------------------------------------------------------------------------------------------

            create_new_assessment:function (input_id, input_assessment) {
                //alert("!!");
                var id;
                var assessment = {
                    id:"",
                    name:"",
                    start_date:"",
                    due_date:"",
                    risks:[],
                    results:[],
                    deleted:"",
                    status:"",
                    owner:"",
                    edited_by:"",
                    assess_map:[]
                };
                if (input_assessment) {
                    id = input_id;
                    assessment.id = id;//input_assessment.id;
                    assessment.name = input_assessment.name;
                    assessment.due_date = input_assessment.due_date;
                    assessment.deleted = false;
                    assessment.start_date = input_assessment.start_date;
                    assessment.status = input_assessment.status;
                    assessment.owner = input_assessment.owner;
                    assessment.assess_map = input_assessment.assess_map;
                    assessment.results = input_assessment.results;
                    assessment.edited_by = streamwork.getViewerId();

                    for (var i = 0; ; i++) {
                        var risk = input_assessment.risks[i];
                        if (risk == undefined) {
                            break;
                        }
                        assessment.risks.push(input_assessment.risks[i]);
                    }
                } else {
                    id = generate_id();
                    var index = id.indexOf("_");
                    index = id.indexOf("_", index + 1);
                    index = id.indexOf("_", index + 1);
                    index = id.indexOf("_", index + 1);
                    index = id.indexOf("_", index + 1);
                    input_id = id.substring(index + 1);
                    assessment.id = id;
                    assessment.deleted = false;
                    assessment.status = "in planning";
                    assessment.risks = [];
                    assessment.owner = streamwork.getViewerId();
                    assessment.edited_by = streamwork.getViewerId();
                    //create the empty assessment
                    controller.create_assessment(assessment);
                }

                var assessment_arrow_id = elementId + '_assessment_arrow_' + id;
                var default_assessment_label_id = elementId + '_default_assessment_label_' + id;
                var placeholder_assessment_id = elementId + '_placeholder_assessment_' + id;
                var assessment_small_id = elementId + '_assessment_small_' + id;
                var assessment_name_id = elementId + '_assessment_name_' + id;
                var assessment_status_id = elementId + '_status_' + id;
                var new_assessment_div = $('<div class="assessment_table_container" id="' + assessment_small_id + '">' +
                    //'<div class="table_left"></div>'+
                    '<div class="table_middle2 resizable_body2">' +
                    '<div class="assessment_header">' +
                    '<div id="' +
                    assessment_name_id +
                    '" class="changeable_title">Assessment Name</div>' +
                    '<div id="' +
                    assessment_status_id +
                    '" class="assessment_status"></div>' +
                    '<img id="' +
                    assessment_arrow_id +
                    '" class="assessment_toogler" src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/close.png"/>' +
                    '<div class="assessment_details" id="' +
                    placeholder_assessment_id +
                    '"></div>' +
                    '</div>' +
                    '</div>' +
                    //'<div class="table_right"></div>'+
                    '</div>').attr('id', assessment.id);

                var assessment_collpase_id = elementId + '_assessment_collapse_' + id;
                var add_risk_id = elementId + '_add_risk_' + id;
                var select_risk_id = elementId + '_select_risk_' + id;
                var due_date_id = elementId + '_due_date_' + id;
                var placeholder_assigned_risks_id = elementId + '_assigned_risks_' + id;
                var start_assessment_id = elementId + '_start_assessment_' + id;
                var new_assessment_collapse = $('<div id="' + assessment_collpase_id + '" class="assessment_table_bottom">' +
                    '<div>' +
                    '</div>' +
                    '<div>' +
                    '<span style="float:right;">' +
                    '<span>Due Date:  </span>' +
                    '<span>' +
                    '<input type="text" id="' +
                    due_date_id +
                    '" >' +
                    '</span>' +
                    '</span>' +
                    '</div>' +
                    '<br><br>' +
                    //'</div>'+
                    '<div class="assessment_form_container">' +
                    '<div class="assigned_risks">' +
                    '<div class="assessment_risk_table_head">Risks:</div>' +
                    '<div>' +
                    '<table width="100%">' +
                    '<tr>' +
                    '<th width="25%">Name</th>' +
                    '<th width="25%">Description</th>' +
                    '<th width="25%">Category</th>' +
                    '<th width="25%">Organization Unit</th>' +
                    '<th width="16px">&nbsp;</th>' +
                    '</tr>' +
                    '</table>' +
                    '</div>' +
                    '<div id="' +
                    placeholder_assigned_risks_id +
                    '">' +
                    '</div>' +
                    '<br>' +
                    '<div>' +
                    '<select id="' + select_risk_id + '" class="option_input_dialog_risks">' +
                    '</select>' +
                    '</div>' +
                    '<br>' +
                    '<div>' +
                    '<div id="' +
                    add_risk_id +
                    '" class="grc_link">Add Risk to Assessment</div>' +
                    '</div>' +
                    '<div  id="' +
                    start_assessment_id +
                    '" width="100%" class="action_button_div">' +
                    '<div class="option_action_btn_right action_button_right" style="background-position: -1px -21px;"></div>' +
                    '<div class="option_action_btn_middle action_button_right option_action_btn_enabled">Click here to start the Assessment</div>' +
                    '<div class="option_action_btn_left action_button_right"></div>' +
                    '</div>' +
                    '<div style="height:30px;float:right;"></div>' +
                    '</div>' +
                    '</div>' +
                    '</div>');

                lipstick.createDatePicker($('#' + due_date_id, new_assessment_collapse), CSTAR.current_user.date_format_pattern, CSTAR.current_user.date_format_symbols, {
                    onSelect:function (dateText, inst) {
                        //check if due date is in the past
                        if (input_id) {
                            //assessment.name = $(this).text();
                            assessment.due_date = $('#' + due_date_id).val();
                            assessment.status = 'in planning';
                            controller.update_assessment(assessment);
                        }
                        else {
                            //assessment.name = $(this).text();
                            assessment.due_date = $('#' + due_date_id).val();
                            assessment.status = 'in planning';
                            controller.assessments.push(assessment);
                            controller.create_assessment(assessment);
                            input_id = id;
                        }
                        ;//end if-else
                    },
                    minDate:new Date()
                })
                //var select_div = $('#' + select_risk_id, new_assessment_collapse);
                //select_div.empty();
                //$('#' + select_risk_id, new_assessment_collapse).empty();
                /*                $('#' + select_risk_id, new_assessment_collapse).append('<option value="0" id="no_risk"> </option> ');
                 for (var i = 0; i < controller.risks.length; i++) {
                 if (controller.risks[i].deleted == false) {
                 var risk = controller.risks[i];
                 select_risk_div_string = '<option id="' + risk.id + '" value="' + risk.id +'>' + risk.name + '</option> ';
                 //alert(select_risk_div_string);
                 $('#' + select_risk_id, new_assessment_collapse).append(select_risk_div_string);
                 }//if
                 }//for
                 */
                //$('#' + select_risk_id, new_assessment_collapse).focus(function() {
                var select_div = $('#' + select_risk_id, new_assessment_collapse);
                select_div.empty();
                $('#' + select_risk_id, new_assessment_collapse).empty();
                $('#' + select_risk_id, new_assessment_collapse).append('<option value="0" id="no_risk"> </option> ');
                for (var i = 0; i < controller.risks.length; i++) {

                    if (controller.risks[i].deleted == false) {
                        var risk = controller.risks[i];
                        var already_assigned = false;
                        //Check if risk already assigned to assessment
                        for (var k in assessment.risks) {
                            var local_risk = assessment.risks[k];
                            if (local_risk == risk.id) {
                                already_assigned = true;
                                break;
                            }
                        }

                        if (already_assigned == true)
                            continue;

                        //additional check for every assessment in controller
                        for (var l = 0; l < controller.assessments.length; l++) {
                            for (var x in controller.assessments[l].risks) {
                                var local_risk = controller.assessments[l].risks[x];
                                if (local_risk == risk.id) {
                                    already_assigned = true;
                                    break;
                                }
                            }
                        }

                        if (already_assigned == true)
                            continue;

                        select_risk_div_string = '<option id="' + risk.id + '" value="' + risk.id + '">' + risk.name + '</option> ';
                        //alert(select_risk_div_string);
                        $('#' + select_risk_id, new_assessment_collapse).append(select_risk_div_string);
                    }//if
                }//for

                //});

                if (assessment.owner != streamwork.getViewerId()) {
                    $('#' + start_assessment_id, new_assessment_collapse).hide();
                    $('#' + due_date_id, new_assessment_collapse).attr('disabled', 'disabled');
                }
                ;

                $('#' + start_assessment_id, new_assessment_collapse).click(function () {
                    if ((assessment.due_date != "") && (assessment.risks.length > 0)) {
                        assessment.status = "running";
                        assessment.start_date = new Date();
                        //assessment.owner = com.streamwork.getViewerId();
                        //$('#' + assessment_collpase_id, new_assessment_div).hide();
                        //$('#' + assessment_status_id, new_assessment_div).text(assessment.status);
                        view.loading_target = new_assessment_div;
                        //controller.update_assessment(assessment);
                        controller.start_risk_assessment(assessment);
                        if (controller.host != null) {
                            controller.start_assessment = {
                                "assessment":assessment,
                                "assessment_collapse_id":assessment_collpase_id,
                                "assessment_status_id":assessment_status_id
                            };
                        }
                        else {
                            controller.update_assessment(assessment);
                            view.run_assessment(id, assessment);
                            $('#' + assessment_collpase_id, new_assessment_div).hide();
                            $('#' + assessment_status_id, new_assessment_div).text(assessment.status);
                        }
                    }
                    else {
                        lipstick.alert("Please give a name for the assessment, a due date and assign at least one Risk.", "impact_name_missing", "Assessment information missing");
                    }

                })

                $('#' + assessment_status_id, new_assessment_div).text(assessment.status);

                if (assessment.status == "running") {
                    $('#' + assessment_collpase_id, new_assessment_div).hide();
                    $('#' + assessment_status_id, new_assessment_div).text(assessment.status);
                }

                if (assessment.due_date) {
                    $('#' + due_date_id, new_assessment_collapse).attr("value", assessment.due_date);
                }
                if (assessment.name) {
                    $("#" + assessment_name_id, new_assessment_div).text(assessment.name);
                }

                if (assessment.status == "in planning") {
                    $("#" + assessment_name_id, new_assessment_div).editable(function (value, settings) {
                        if (!value || !value.length || $.trim(value) === '') {
                            //$(this).text(this.revert);
                            return;
                        }
                        //controller.update_title(value, true);
                    }, {
                        type:'text',
                        onreadytoedit:function () {

                        },
                        onfinishededit:function () {
                            if ($(this).is('.title_editable')) {
                                $(this).removeClass('title_editable');
                            }
                            if ($(this).text() !== "Assessment Name") {
                                $(this).css('color', '#333333');
                                if (input_id) {
                                    assessment.name = $(this).text();
                                    assessment.due_date = $('#' + due_date_id).val();
                                    assessment.status = 'in planning';
                                    //controller.update_assessment(id, $(this).text(), $('#' + due_date_id).text(), placeholder_assessment_id, false, 'planned');
                                    controller.update_assessment(assessment);
                                }
                                else {
                                    assessment.name = $(this).text();
                                    assessment.due_date = $('#' + due_date_id).val();
                                    assessment.status = 'in planning';
                                    controller.assessments.push(assessment);
                                    controller.create_assessment(assessment);
                                    input_id = id;
                                    //controller.create_assessment(id, $(this).text(), $('#' + due_date_id).text(), placeholder_assessment_id, false, 'planned');
                                }
                            }
                            //$(this).css('padding-top', '2px');
                            //$(this).css('min-height', '15px');
                        },
                        //height: '15px',
                        width:'130px',
                        //cssclass: 'buttonInplaceEdit',
                        tooltip:'Click to edit...',
                        placeholder:"Assessment Name"
                    });//edit Assessment Name
                    $("#" + assessment_name_id, new_assessment_div).hover(function () {
                            //if ( $("#AssessmentName").length < 1) {
                            var assessmentName = $("#" + assessment_name_id);
                            assessmentName.addClass('title_editable');
                            //}
                        }, //hover start
                        function () {
                            var assessmentName = $("#" + assessment_name_id);
                            assessmentName.removeClass('title_editable');
                        }//hover ended
                    );//assessmentName.hover
                    $("#" + assessment_name_id, new_assessment_div).click(function () {
                        var assessmentName = $("#" + assessment_name_id);
                        assessmentName.removeClass('title_editable');
                        if ($(this).val() === "New Assessment") {
                            $(this).val('');
                        }
                    });//AssessmentName.click
                }//if in planning
                $("#" + add_risk_id, new_assessment_collapse).click(function () {
                    if ($('#' + select_risk_id + ' :selected', new_assessment_collapse).val() != 0) {
                        /*
                         for (var i = 0; i < assessment.risks.length; i++) {
                         if (assessment.risks[i] == $('#' + select_risk_id + ' :selected', new_assessment_collapse).val()) {
                         lipstick.alert("This Risk is already assigned to this Assessment.");
                         return;
                         }
                         }
                         */
                        assessment.risks.push($('#' + select_risk_id + ' :selected', new_assessment_collapse).val());
                        view.add_assigned_risk(placeholder_assigned_risks_id, $('#' + select_risk_id + ' :selected', new_assessment_collapse).val());
                        $('#' + select_risk_id + ' :selected', new_assessment_collapse).remove();
                        $('#' + select_risk_id, new_assessment_collapse).attr("value", 0);


                        //alert(($('#' + select_risk_id + ' :selected', new_assessment_collapse).val()));
                        controller.update_assessment(assessment);
                        //controller.add_risk(assessment_id, $('select_risk_id : selected').val());
                    }
                });//add_risk.click
                //new_assessment_div.data( "id", id );
                $('#' + assessment_arrow_id, new_assessment_div).click(function () {
                    view.hide_new_assessment(placeholder_assessment_id, assessment_arrow_id, true, assessment_name_id);
                })
                //alert($('#'+ placeholder_assessment_id, new_assessment_div));
                $('#' + placeholder_assessment_id, new_assessment_div).append(new_assessment_collapse);
                $('#placeholder_create_new_assessment').append(new_assessment_div);

                for (var i in assessment.risks) {
                    view.add_assigned_risk(placeholder_assigned_risks_id, assessment.risks[i]);
                }

                if (input_id) {
                    if (assessment.status == "running") {
                        $('#' + assessment_collpase_id, new_assessment_div).hide();
                        view.run_assessment(input_id, assessment);
                    }
                    if (assessment.status == "closed") {
                        $('#' + assessment_collpase_id, new_assessment_div).hide();
                        if (controller.host != null) {
                            controller.aggregate_results(assessment);
                        }
                        else {
                            if (!assessment.results.length) {
                                controller.aggregate_results(assessment);
                            }

                            view.show_assessment_results(id, assessment);
                        }
                    }
                }
                else {
                    controller.create_assessment_container(placeholder_assessment_id, true, assessment_arrow_id, assessment_name_id);
                }
                $('.resizable_head').width((view.div.width() - 13));
                $('.resizable_body').width((view.div.width() - 5));
                $('.resizable_body2').width(view.div.width());
                /*    if (collapsed == false){
                 view.hide_new_assessment(placeholder_assessment_id , assessment_arrow_id, assessment_id);
                 }*/
            }, //create_new_assessment
            //------------------------------------------------ RUN RISK ASSESSMENT ------------------------------------------------
            //     creates the view to run the risk assessment
            //---------------------------------------------------------------------------------------------------------------------
            run_assessment:function (input_id, input_assessment) {
                var id = input_id;
                var radio_buttons = [];
                var assessment = {
                    id:input_assessment.id,
                    name:input_assessment.name,
                    start_date:input_assessment.start_date,
                    due_date:input_assessment.due_date,
                    risks:[],
                    deleted:input_assessment.deleted,
                    status:input_assessment.status,
                    owner:input_assessment.owner,
                    assess_map:input_assessment.assess_map,
                    results:[],
                    edited_by:com.streamwork.getViewerId()
                };//assessment
                for (var i = 0; i < input_assessment.risks.length; i++) {
                    assessment.risks.push(input_assessment.risks[i]);
                }//for
                var already_voted = "";
                var persons_results = {};
                for (var i = 0; i < assessment.assess_map.length; i++) {
                    if (assessment.assess_map[i].user == com.streamwork.getViewerId()) {
                        persons_results = assessment.assess_map[i];
                        already_voted = "DISABLED";
                    }
                }

                //ADDITIONAL CODING BY D053422
                var residual_risk_select_id = elementId + '_residual_risk_select_' + id;
                var mitigation_select_id = elementId + '_mitigation_select_' + id;

                var residual_risk_options = '';
                //Initial level
                residual_risk_options = residual_risk_options + '<option id=0 value=0"> </option>';
                for (var i = 0; i < controller.residual_risk_levels.length; i++) {
                    //display only submitted value
                    if (already_voted) {
                        var assessment_map;
                        for (var aid = 0; aid < assessment.assess_map.length; aid++) {
                            if (assessment.assess_map[aid].user == streamwork.getViewerId()) {
                                assessment_map = assessment.assess_map[aid];
                                break;
                            }
                        }
                        var residual_val = assessment_map.residual_risk_vote;
                        var voted_level = controller.residual_risk_levels[residual_val - 1];
                        residual_risk_options = '<option id="' + voted_level.value + '" value="' + voted_level.id + '">' + voted_level.text + '</option>';
                        break;
                    }
                    var aLevel = controller.residual_risk_levels[i];
                    residual_risk_options = residual_risk_options + '<option id="' + aLevel.value + '" value="' + aLevel.id + '">' + aLevel.text + '</option>';
                }
                //$('#' + residual_risk_select_id, additionalFieldsString).append(residual_risk_options);
                var mitigation_effectiveness_options = '';
                //Initial level
                mitigation_effectiveness_options = mitigation_effectiveness_options + '<option id=0 value=0 > </option>';
                for (var i = 0; i < controller.mitigation_effectiveness_levels.length; i++) {
                    //display only submitted value
                    if (already_voted) {
                        var assessment_map;
                        for (var aid = 0; aid < assessment.assess_map.length; aid++) {
                            if (assessment.assess_map[aid].user == streamwork.getViewerId()) {
                                assessment_map = assessment.assess_map[aid];
                                break;
                            }
                        }
                        var mitigation_val = assessment_map.mitigation_effectiveness_vote
                        var voted_level = controller.mitigation_effectiveness_levels[mitigation_val - 1];
                        mitigation_effectiveness_options = '<option id="' + voted_level.value + '" value="' + voted_level.id + '">' + voted_level.text + '</option>';
                        break;
                    }
                    var aLevel = controller.mitigation_effectiveness_levels[i];
                    mitigation_effectiveness_options = mitigation_effectiveness_options + '<option id="' + aLevel.value + '" value="' + aLevel.id + '">' + aLevel.text + '</option>';
                }

                var additionalFieldsString = '<br><div><table width="95%" align="center"><tr>' +
                    '<span width="50%" align="left"><th>Mitigation Effectiveness:</th><td><select id="' + mitigation_select_id + '"' + already_voted + '>' + mitigation_effectiveness_options + '</select></td></span>' +
                    '<span width="50%" align="left"><th>Residual Risk Status:</th><td><select id="' + residual_risk_select_id + '"' + already_voted + '>' + residual_risk_options + '</select></td></span>' +
                    '</tr></table></div>';

                //END OF ADDITIONAL CODING

                var placeholder_assessment_id = elementId + '_placeholder_assessment_' + id;
                var running_assessment_collapse_id = elementId + '_run_assessment_collapse_' + id;
                var running_assessment_div = $('<div>' +
                    '<div id="' +
                    running_assessment_collapse_id +
                    '" class="assessment_table_bottom">' +
                    '</div>' +
                    '<div>' +
                    '<span style="float:right;">' +
                    '<span>Due Date:  </span>' +
                    '<span>' +
                    assessment.due_date +
                    '</span>' +
                    '</span>' +
                    '</div>' +
                    '<br>' + '</div>');
                var column_width = (100 / (controller.impact_levels.length + 1));
                var impact_levels_string = '<tr>' +
                    '<th width="' +
                    column_width +
                    '%">&nbsp;</th>';

                var assess_map_entry = {
                    user:com.streamwork.getViewerId(),
                    risks:[],
                    finished:"",
                    mitigation_effectiveness_vote:"",
                    residual_risk_vote:""
                };
                for (var i = 0; i < controller.impact_levels.length; i++) {
                    impact_levels_string = impact_levels_string + '<th width="' + column_width + '%">' + controller.impact_levels[i].text + '</th>';
                }//imapct levels for header
                impact_levels_string = impact_levels_string + '</tr>';

                for (var i = 0; i < assessment.risks.length; i++) {
                    for (var j = 0; j < controller.risks.length; j++) {
                        if (controller.risks[j].id == assessment.risks[i]) {
                            var risk = controller.risks[j];
                            var risk_vote = {
                                id:risk.id,
                                probability:"",
                                impact_votes:[]
                            }
                            var assess_risk = $('<fieldset><legend>' + risk.name + '</legend>' +
                                //'<div>' + risk.name + '</div>'+
                                //'<table class="assess_table" id="' + assessment.risks[i] + '"></table>' +
                                '</fieldset>');
                            //$('#' + assessment.risks[i], assess_risk).append(impact_levels_string);
                            var impact_table_string = '<table class="assess_table" id="' + assessment.risks[i] + '">';
                            impact_table_string = impact_table_string + impact_levels_string;

                            var user_choice = false;
                            if (already_voted && assessment.assess_map) {
                                for (var aid = 0; aid < assessment.assess_map.length; aid++) {
                                    if (assessment.assess_map[aid].user == streamwork.getViewerId()) {
                                        user_choice = assessment.assess_map[aid];
                                    }
                                }
                            }

                            //fix for impacts sequence in firefox
                            try {
                                for (var k = 0; ; k++) {
                                    var impact = risk.impacts[k];
                                    var vote_impact = {
                                        name:impact.name,
                                        value:""
                                    }
                                    var radio_button_entry = {
                                        risk:risk.id,
                                        impact:impact.name,
                                        group_name:risk.id + '_' + impact.name
                                    }

                                    radio_buttons.push(radio_button_entry);
                                    risk_vote.impact_votes.push(vote_impact);

                                    var impact_select_option_string = '<tr><td width="' + column_width + '%">' + impact.name + '</td>';
                                    for (var l = 0; l < controller.impact_levels.length; l++) {
                                        var checked_flag = '';
                                        if (user_choice && user_choice['risks'][i]['impact_votes'][k]['value'] == controller.impact_levels[l].value) {
                                            checked_flag = 'checked';
                                        }
                                        impact_select_option_string = impact_select_option_string + '<td width="' + column_width + '%"><input class="radio_button_impact_level" type="radio" name="' + assessment.id + '___' + radio_button_entry.group_name + '" ' + already_voted + ' value="' + controller.impact_levels[l].value + '" ' + checked_flag + '></td>';
                                    }//imapct levels for radio buttons
                                    impact_select_option_string = impact_select_option_string + '</tr>';
                                    //var impact_select_option_div = $(impact_select_option_string);
                                    //$('#' + assessment.risks[i], assess_risk).append(impact_select_option_string);
                                    impact_table_string = impact_table_string + impact_select_option_string;

                                    impact_select_option_string = '';
                                }//impact level of one single risk
                            } catch (e) {

                            }
                            impact_table_string = impact_table_string + '</table>';
                            assess_risk.append(impact_table_string);

                            $('.radio_button_impact_level', assess_risk).change(function () {
                                for (var m = 0; m < radio_buttons.length; m++) {
                                    var radio_button_group = radio_buttons[m];
                                    if (radio_button_group.group_name == this.name.split('___', 2)[1]) {
                                        //alert (radio_button_group.risk + " " + radio_button_group.impact);
                                        for (var n = 0; n < assess_map_entry.risks.length; n++) {
                                            if (assess_map_entry.risks[n].id == radio_button_group.risk) {
                                                var risk_votes = assess_map_entry.risks[n];
                                                for (var o = 0; o < risk_votes.impact_votes.length; o++) {
                                                    var impact_votes = risk_votes.impact_votes[o];
                                                    if (impact_votes.name == radio_button_group.impact) {
                                                        impact_votes.value = this.value;
                                                    }

                                                }//loop above all impacts of this risk
                                            }//if radio button group belongs to this risk
                                        }//loop above all risks
                                        break;
                                    }//if radio button group found
                                }//loop above all radio button groups
                            });//impact value changed

                            var probability_table_id = assessment.risks[i] + '_probability_table';
                            var probability_table_string = '<br><table class="assess_table" id="' + probability_table_id + '">';

                            var probability_table_head = '<tr><th width="' + column_width + '"></th>';
                            var column_width_prob = (100 / (controller.probability_levels.length + 1));
                            for (var m = 0; m < controller.probability_levels.length; m++) {
                                probability_table_head = probability_table_head + '<th width="' + column_width_prob + '%">' + controller.probability_levels[m].text + '</th>';
                            }//probability levels for header
                            probability_table_head = probability_table_head + '</tr>';

                            probability_table_string = probability_table_string + probability_table_head;

                            var probability_select_option_string = '<tr><td width="' + column_width + '%">Probability</td>';

                            for (var m = 0; m < controller.probability_levels.length; m++) {
                                var checked_flag = '';
                                if (user_choice && user_choice['risks'][i]['probability'] == controller.probability_levels[m].value) {
                                    checked_flag = 'checked';
                                }
                                probability_select_option_string = probability_select_option_string + '<td width="' + column_width_prob + '%"><input class="radio_button_probability_level" type="radio" name="probability_' + assessment.id + '___' + risk.id + '" ' + already_voted + ' value="' + controller.probability_levels[m].value + '" ' + checked_flag + '></td>';
                            }//probability levels for radio buttons
                            probability_select_option_string = probability_select_option_string + '</tr>';

                            probability_table_string = probability_table_string + probability_select_option_string;

                            probability_table_string = probability_table_string + '</table><br><br>';
                            assess_risk.append(probability_table_string);

                            $('.radio_button_probability_level', assess_risk).change(function () {
                                var radio_button_id = this.name.split('___', 2)[1];
                                var index = radio_button_id.indexOf("_");
                                var risk_id = radio_button_id.substring(index + 1);

                                for (var n = 0; n < assess_map_entry.risks.length; n++) {
                                    if (assess_map_entry.risks[n].id == risk_id) {
                                        assess_map_entry.risks[n].probability = this.value;
                                    }//if risk found set probability
                                }//search vor risk the probability radio buttons belong to
                            });//probability changed
                            assess_map_entry.risks.push(risk_vote);
                            running_assessment_div.append(assess_risk);
                        }//assigned risk found
                    }//search for assigned risk
                }//loop above all assigned risks
                var done_div_id = elementId + '_done_' + id;
                var done_div = $('<div>You already completed this Assessment</div>').attr('id', done_div_id);
                running_assessment_div.append(done_div);

                if (already_voted == "") {
                    done_div.hide();
                }
                var submit_div_id = elementId + '_submit_' + id;
                var submit_div_string = '<br><div ' + already_voted + ' class="action_button_div">' +
                    '<div class="option_action_btn_right action_button_left"></div>';
                if (already_voted == "") {
                    submit_div_string = submit_div_string + '<div id="' + submit_div_id + '" class="option_action_btn_middle action_button_left option_action_btn_enabled">Submit Assessment</div>';
                }
                else {
                    submit_div_string = submit_div_string + '<div class="option_action_btn_middle action_button_left option_action_btn_disabled">Submit Assessment</div>';
                }

                submit_div_string = submit_div_string + '<div class="option_action_btn_left action_button_left" style="background-position: -1px -21px;"></div>' +
                    //'<input class="assessment_button" style="color:#000000;border-color:gray;"  ' + already_voted + ' type="button" value="Submit Assessment" id="' + submit_div_id + '">'+
                    '</div>' +
                    '<br>';
                var submit_div = $(submit_div_string);

                $('#' + submit_div_id, submit_div).click(function () {
                    //TODO
                    var valid_submit = true;
                    for (var i = 0; i < assess_map_entry.risks.length; i++) {
                        var risk = assess_map_entry.risks[i];
                        for (var j = 0; j < risk.impact_votes.length; j++) {
                            var impact_vote = risk.impact_votes[j];
                            var prob = risk.probability;
                            if (impact_vote.value == "" || prob == "") {
                                lipstick.alert("Please rate all impacts and probabilities of the given risks.");
                                return;
                            }//if impact has been rated
                        }//all impacts of a certain risk
                    }//all risks of the assessment

                    //ADDITIONAL CODING BY D053422
                    //get selected mitigation effectiveness
                    var selectedMitigationEffectiveness = $('#' + mitigation_select_id + ' option:selected');
                    var mitigation_effectiveness = selectedMitigationEffectiveness.attr('id');
                    if (mitigation_effectiveness == "0") {
                        lipstick.alert("Please select mitigation effectiveness from dropdown list.");
                        return;
                    }
                    //get selected residual risk
                    var selectedResidualRisk = $('#' + residual_risk_select_id + ' option:selected');
                    var residual_risk = selectedResidualRisk.attr('id');
                    if (residual_risk == "0") {
                        lipstick.alert("Please select residual risk from dropdown list.");
                        return;
                    }

                    assess_map_entry.mitigation_effectiveness_vote = selectedMitigationEffectiveness.attr('id');
                    $('#' + mitigation_select_id).attr('disabled', 'disabled');

                    assess_map_entry.residual_risk_vote = selectedResidualRisk.attr('id');
                    $('#' + residual_risk_select_id).attr('disabled', 'disabled');
                    //set them in assess map entry

                    //END OF ADDITIONAL CODING

                    if (controller.host != null) {
                        controller.submit_to_rm(assess_map_entry);
                    }
                    assessment.assess_map.push(assess_map_entry);
                    controller.update_assessment(assessment);
                    var div_button = $('.option_action_btn_enabled', submit_div);
                    div_button.removeClass('option_action_btn_enabled').addClass('option_action_btn_disabled');
                    $('.radio_button_probability_level').attr("disabled", "disabled");
                    $('#' + submit_div_id).attr(already_voted);
                    $('#' + submit_div_id).unbind('click');
                    $('.radio_button_impact_level').attr("disabled", "disabled");
                    $('#' + done_div_id).show();

                    //update number of submitted assessments
                    $('#' + number_of_votings_id).empty();
                    $('#' + number_of_votings_id).append('Submitted Assessments: ' + assessment.assess_map.length + ' of ' +
                        streamwork.getParticipants().length + ' participant/s&nbsp;&nbsp;');

                    var tooltip_string = '<div>';
                    for (var i = 0; i < assessment.assess_map.length; i++) {
                        var anEntry = assessment.assess_map[i];
                        var additionalString = '<div>' + streamwork.getParticipantById(anEntry.user).displayName + '</div>';
                        tooltip_string += additionalString;
                    }
                    ;
                    tooltip_string += '</div>';
                    var tooltip = $(tooltip_string);
                    var offset = {
                        x:-30,
                        y:-50
                    };
                    var tooltip_origin = $('#' + number_of_votings_id, close_div);
                    lipstick.tooltip(tooltip_origin, tooltip, offset);
                });
                running_assessment_div.append(additionalFieldsString);//ADDITIONAL CODING BY D053422
                running_assessment_div.append(submit_div);

                var close_div_id = elementId + '_close_' + id;
                var number_of_votings_id = elementId + '_numberOfVotings_' + id;

                if (assessment.owner == com.streamwork.getViewerId()) {
                    var close_div = $('<br>' +
                        '<div style="float:right;">' +
                        '<div style="float:left;" id="' + number_of_votings_id + '">Submitted Assessments: ' + assessment.assess_map.length + ' of ' + streamwork.getParticipants().length + ' participant/s&nbsp;&nbsp;</div>' +
                        '<div class="action_button_div">' +
                        '<div class="option_action_btn_right action_button_left"></div>' +
                        '<div id="' +
                        close_div_id +
                        '" class="option_action_btn_middle action_button_left option_action_btn_enabled">Close Assessment</div>' +
                        '<div class="option_action_btn_left action_button_left" style="background-position: -1px -21px;"></div>' +
                        '<br>' +
                        //'<input class="assessment_button" style="color:#000000;border-color:gray;" type="button" value="Close Assessment" id="' + close_div_id + '">'+
                        '</div>' +
                        '</div>' +
                        '<div style="height:30px;float:right;"></div>');

                    if (assessment.assess_map.length > 0) {
                        var tooltip_string = '<div>';
                        for (var i = 0; i < assessment.assess_map.length; i++) {
                            var anEntry = assessment.assess_map[i];
                            var additionalString = '<div>' + streamwork.getParticipantById(anEntry.user).displayName + '</div>';
                            tooltip_string += additionalString;
                        }
                        ;
                        tooltip_string += '</div>';
                        var tooltip = $(tooltip_string);
                        var offset = {
                            x:-30,
                            y:-50
                        };
                        var tooltip_origin = $('#' + number_of_votings_id, close_div);
                        lipstick.tooltip(tooltip_origin, tooltip, offset);
                    }
                    ;


                    var close_assessment_info = $('<div></div>');
                    $('#' + close_div_id, close_div).click(function () {
                        if (assessment.assess_map.length == 0) {
                            lipstick.alert('Please, make an assessment before start.');
                            return;
                        }
                        var warning_text = 'Once you close the assessment, participants will no longer be able to assess the risks.', warning_string = '<div class="grc_warning_body"><div class="grc_warning_icon_container"><div class="grc_warning_icon"/></div>' +
                            '<div class="grc_warning_message_container"><div class="grc_warning_content_div"></div>' +
                            warning_text +
                            '<div class="grc_warning_content_div"></div></div></div>', warning = $(warning_string), options = {
                            onOK:function () {
                                running_assessment_div.hide();
                                //refresh the data
                                //controller.get_assessment_for_close(assessment.id);

                                assessment.status = "closed";

                                controller.aggregate_results(assessment);
                                controller.update_assessment(assessment);
                                if (controller.host == null) {
                                    view.show_assessment_results(input_id, assessment);
                                }
                            }, //onOK
                            title:"Close Assessment",
                            okLabel:"OK",
                            cancelLabel:"Cancel"
                        }
                        lipstick.dialog(warning, options);
                    });//on Assessment Close
                    running_assessment_div.append(close_div);
                }//if the viewer has started the assessment
                $('#' + placeholder_assessment_id).append(running_assessment_div);

                if ((assessment.status == "closed") && (controller.host == null)) {
                    running_assessment_div.hide();
                    view.show_assessment_results(id, assessment);
                }
            }, //run assessment
            //------------------------------------------------ SHOW ASSESSMENT RESULTS ------------------------------------------------
            //     shows the results of a assessment
            //---------------------------------------------------------------------------------------------------------------------
            show_assessment_results:function (input_id, input_assessment) {
                var id = input_id;
                var assessment = {
                    id:input_assessment.id,
                    name:input_assessment.name,
                    start_date:input_assessment.start_date,
                    due_date:input_assessment.due_date,
                    risks:[],
                    deleted:input_assessment.deleted,
                    status:input_assessment.status,
                    owner:input_assessment.owner,
                    assess_map:input_assessment.assess_map,
                    results:input_assessment.results
                };//assessment
                var assessment_status_id = elementId + '_status_' + id;
                var placeholder_assessment_id = elementId + '_placeholder_assessment_' + id;
                var result_div_id = elementId + '_result_div_' + id;
                var prob_level_tab_id = elementId + '_prob_level_tab' + id;
                var impact_level_tab_id = elementId + '_impact_level_tab' + id;
                var result_panel_id = elementId + '_result_panel_' + id;

                var result_panel_pic_id = elementId + '_result_panel_pic_' + id;
                var results_view_header_id = elementId + '_results_view_header_' + id;
                var back_to_overview_id = elementId + '_back_to_overview_' + id;


                //ADDITIONAL CODING BY D053422
                var additionalParametersResult = assessment.results[assessment.results.length - 1];

                //c5139482 calculate mitigation effectiveness and residual risk values in connected mode
                if (controller.host != null) {
                    var aggregated_mitigation_vote = 0;
                    var aggregated_residual_risk_vote = 0;
                    for (var i = 0; i < input_assessment.assess_map.length; i++) {
                        var assess_map_entry = input_assessment.assess_map[i];
                        var person_assessed_risks = [];
                        aggregated_mitigation_vote = controller.run_aggregation_method(aggregated_mitigation_vote,
                            assess_map_entry.mitigation_effectiveness_vote);
                        aggregated_residual_risk_vote = controller.run_aggregation_method(aggregated_residual_risk_vote,
                            assess_map_entry.residual_risk_vote);
                    }

                    additionalParametersResult.mitigation_value = aggregated_mitigation_vote / input_assessment.assess_map.length;
                    additionalParametersResult.residual_value = aggregated_residual_risk_vote / input_assessment.assess_map.length;
                    additionalParametersResult.mitigation_max_value = controller.mitigation_effectiveness_levels.length;
                    additionalParametersResult.residual_max_value = controller.residual_risk_levels.length;
                }

                var width_mitigation_left = ( parseInt(additionalParametersResult.mitigation_value) / parseInt(additionalParametersResult.mitigation_max_value) ) * 100;
                var width_mitigation_right = 100 - width_mitigation_left;
                //mitigation .. less is worse
                if (width_mitigation_left < 33.3) {
                    //green
                    mitigation_barcolor = '#23B000';
                } else if (width_mitigation_left < 66.6) {
                    //orange
                    mitigation_barcolor = '#FF8000';
                } else {
                    //red
                    mitigation_barcolor = '#D41500';
                }
                ;

                var width_residual_left = ( parseInt(additionalParametersResult.residual_value) / parseInt(additionalParametersResult.residual_max_value) ) * 100;
                ;
                var width_residual_right = 100 - width_residual_left;
                //residual .. less is better
                if (width_residual_left < 33.3) {
                    //green
                    residual_barcolor = '#23B000';
                } else if (width_residual_left < 66.6) {
                    //orange
                    residual_barcolor = '#FF8000';
                } else {
                    //red
                    residual_barcolor = '#D41500';
                }
                ;
                var mitigationProgressId = elementId + '_mitigationpogress_' + id;
                var residualProgressId = elementId + '_residualpogress_' + id;
                var additional_results_string = '' +
                    '<div style="margin:auto; width:80%;">' +
                    '<table style="width:100%;">' +
                    '<tr>' +
                    '<th style="vertical-align:middle; text-align:right; min-width:150px;">Mitigation Effectiveness&nbsp&nbsp</th>' +
                    '<td style="text-align:right; width:100%;">' +
                    '<table style="width:100%;">';
                if (controller.mitigation_effectiveness_levels.length > 0) {
                    additional_results_string = additional_results_string +
                        '<tr><th style="text-align:left; min-width:34%;">' + controller.mitigation_effectiveness_levels[0].text + '</th><th style="text-align:center; min-width:32%;">' + '' + '</th><th style="text-align:right; min-width:34%">' + controller.mitigation_effectiveness_levels[controller.mitigation_effectiveness_levels.length - 1].text + '</th></tr>';
                }
                additional_results_string = additional_results_string +
                    '<tr style="width:100%;">' +
                    '<table id="' + mitigationProgressId + '" style="height:20px; width:100%; border:1px solid black;"><tr>' +
                    '<td style="background-color:' + mitigation_barcolor + '; width:' + width_mitigation_left + '%;"></td>' +
                    '<td style="">' +
                    '</tr></table>' +
                    '</tr>' +
                    '</table>' +
                    '</td>' +
                    '</tr>' +
                    '</table>' +
                    '<table  style="width:100%;">' +
                    '<tr>' +
                    '<th style="vertical-align:middle; text-align:right; min-width:150px;">Residual Risk Status&nbsp&nbsp</th>' +
                    '<td style="text-align:right; width:100%;">' +
                    '<table style="width:100%;">';
                if (controller.residual_risk_levels.length > 0) {
                    additional_results_string = additional_results_string +
                        '<tr><th style="text-align:left; min-width:34%;">' + controller.residual_risk_levels[0].text + '</th><th style="text-align:center; min-width:32%;">' + '' + '</th><th style="text-align:right; min-width:34%">' + controller.residual_risk_levels[controller.residual_risk_levels.length - 1].text + '</th></tr>';
                }
                additional_results_string = additional_results_string +
                    '<tr style="width:100%;">' +
                    '<table id="' + residualProgressId + '" style="height:20px; width:100%; border:1px solid black;"><tr>' +
                    '<td style="background-color:' + residual_barcolor + '; width:' + width_residual_left + '%;"></td>' +
                    '<td style="">' +
                    '</tr></table>' +
                    '</tr>' +
                    '</table>' +
                    '</td>' +
                    '</tr>' +
                    '</table>' +
                    '</div><br>';

                //END OF ADDITIONAL CODING

                //changed by C5163319
                //check if the chart already exists
                if (!$('#' + result_panel_id).length) {
                    //it doesn't exist, so add it
                    var result_div = $('<br><br>' +
                        '<div id="' + back_to_overview_id + '" class="grc_link switch_view result_panel_navigation" >Back to Overview</div>' +
                        '<div id="' + results_view_header_id + '" class="result_view_header"></div>' +
                        '<div id="' + result_div_id + '"></div>' +
                        '<div class="result_chart">' +
                        '<div class="container_left_axis rotate180" id="container">' +
                        '<div class="axis_title">Probability</div>' +
                        '<div>' +
                        '<table class="result_axis_table">' +
                        '<tr width="100%" id="' + prob_level_tab_id + '"></tr>' +
                        '</table>' +
                        '</div>' +
                        '</div>' +
                        '<div class="container_bottom_axis" id="container">' +
                        '<div>' +
                        '<table class="result_axis_table">' +
                        '<tr width="100%" id="' + impact_level_tab_id + '"></tr>' +
                        '</table>' +
                        '</div>' +
                        '<div class="axis_title">Impacts</div>' +
                        '</div>' +
                        '<div class="result_panel" id="' + result_panel_id + '">' +
                        '<div class="result_panel_all_in_one">' +
                        '<img class="result_panel_pic" ' +
                        'src="http://coevi131.wdf.sap.corp:8000/sap/bc/bsp/sap/ZCOLL_ASS_SW/images/heatmap.png" id="' +
                        result_panel_pic_id +
                        '">' +
                        '</div>' +
                        '</div>' +
                        '</div>' + additional_results_string);

                    $('#' + assessment_status_id).text(assessment.status);
                    var impact_level_tab = $('#' + impact_level_tab_id, result_div);
                    var impact_level_width = (100 / (controller.impact_levels.length - (-1)));
                    //impact_level_tab.append('<td width="' + impact_level_width + '%">&nbsp;</td>');
                    impact_level_tab.append('<td width="10%">&nbsp;</td>');
                    for (var i = 0; i < controller.impact_levels.length; i++) {
                        impact_level_tab.append('<td width="' + impact_level_width + '%">' + controller.impact_levels[i].text + '</td>');
                    }


                    var prob_level_tab = $('#' + prob_level_tab_id, result_div);
                    var prob_level_width = (100 / controller.probability_levels.length) - 5;
                    prob_level_tab.append('<td width="5%">&nbsp;</td>');
                    for (var i = 0; i < controller.probability_levels.length; i++) {
                        prob_level_tab.append('<td width="' + prob_level_width + '%">' + controller.probability_levels[i].text + '</td>');
                    }

                    $('#' + placeholder_assessment_id).append(result_div);
                    $('#' + back_to_overview_id).click(function () {
                        $('#' + results_view_header_id).text("Overview");
                        $('.result_chart_participant').hide();
                        $('.result_chart_risk').show();
                        $('#' + back_to_overview_id).removeClass('switch_view_show').addClass('switch_view');
                    });

                    view.draw_grid(result_panel_id);
                }
                //end added by C5163319

                view.display_risks_in_chart(assessment, result_panel_id, results_view_header_id);
            }, //show_assessment_results
            //------------------------------------------------DRAW GRID---------------------------------------------------------------
            //		draw grid
            //------------------------------------------------------------------------------------------------------------------------
            draw_grid:function (parent_div_id) {
                var parent_width = $('#' + parent_div_id).width();
                var parent_height = $('#' + parent_div_id).height();
                var height_delta = 100 / controller.probability_levels.length;
                var width_delta = 100 / controller.impact_levels.length;
                var grid_height = height_delta;
                var grid_width = width_delta;

                //hard hack for the iPad
                $(".result_panel_pic").css({"height":"495"});
                //draw horizontal lines
                for (var i = 0; i < controller.probability_levels.length; i++) {
                    heatmap_grid = $('<div style="position:absolute;width:100%;height:' + grid_height + '%;border:1px solid #000;z-index:2"></div>');
                    $("#" + parent_div_id).append(heatmap_grid);
                    grid_height += height_delta;
                }
                //draw vertical lines
                for (var i = 0; i < controller.impact_levels.length; i++) {
                    heatmap_grid = $('<div style="position:absolute;width:' + grid_width + '%;height:' + parent_height + 'px;border:1px solid #000;z-index:2"></div>');
                    $("#" + parent_div_id).append(heatmap_grid);
                    grid_width += width_delta;
                }
            },
            //------------------------------------------------ DISPLAY RISKS IN CHART ------------------------------------------------
            //     displays Risks in Chart
            //---------------------------------------------------------------------------------------------------------------------
            display_risks_in_chart:function (input_assessment, parent_div_id, results_view_header_id) {
                //pretty_alert('input_assessment.results', input_assessment.results);
                var panel_div = $('#' + parent_div_id);

                //In standalone, the last element of input_assessment.results is different
                var iter_length = controller.host ? input_assessment.results.length : input_assessment.results.length - 1;

                var avarage_points_x = {};
                var avarage_points_y = {};

                for (var i = 0; i < iter_length; i++) {
                    if (!(input_assessment.results[i].risk in avarage_points_x)) {
                        avarage_points_x[input_assessment.results[i].risk] = [];
                    }
                    if (!(input_assessment.results[i].risk in avarage_points_y)) {
                        avarage_points_y[input_assessment.results[i].risk] = [];
                    }

                    var position_y = 100 - (input_assessment.results[i].probability_value / controller.probability_levels.length * 100);
                    position_y += (100 / controller.probability_levels.length / 2) - 3;//display more accurately

                    avarage_points_y[input_assessment.results[i].risk].push(position_y);

                    var divider = 0;
                    for (var j = 0; j < controller.risks.length; j++) {
                        if (controller.risks[j].id == input_assessment.results[i].risk) {
                            for (var k in controller.risks[j].impacts) {
                                divider++;
                            }
                        }
                    }

                    var impact_value;
                    if (controller.host != null) {
                        impact_value = input_assessment.results[i].impact_value / divider;
                        //impact_value = impact_value / input_assessment.results.length;
                        var position_x = ((( impact_value / controller.impact_levels.length) * 100));// -5);
                    }
                    else {
                        impact_value = input_assessment.results[i].impact_value / divider;
                        impact_value = impact_value / input_assessment.results[i].participant.length;
                        var position_x = ((( impact_value / controller.impact_levels.length) * 100));// -5);
                    }
                    position_x -= (100 / controller.impact_levels.length / 2) + 3;//display more accurately

                    if (position_x < 0) {
                        position_x = 0;
                    }
                    if (position_y > 90) {
                        position_y = 90;
                    }
                    avarage_points_x[input_assessment.results[i].risk].push(position_x);
                }

                for (risk in avarage_points_x) {

                    var x = 0;
                    for (var x_i = 0; x_i < avarage_points_x[risk].length; x_i++) {
                        x += avarage_points_x[risk][x_i];
                    }
                    x /= avarage_points_x[risk].length;

                    var y = 0;
                    for (var y_i = 0; y_i < avarage_points_y[risk].length; y_i++) {
                        y += avarage_points_y[risk][y_i];
                    }
                    y /= avarage_points_y[risk].length;

                    var new_risk_div = $('<div class="result_chart_risk" id="' + risk + '"' +
                        ' style="top:' + y + '%; ' + 'left:' + x + '%;"></div>');

                    for (var j = 0; j < controller.risks.length; j++) {
                        var already_displayed = false;
                        if (controller.risks[j].id == risk) {
                            var tooltip_div = $('<div width="50px">Name: ' + controller.risks[j].name + '</div>' +
                                '<div>Description: ' + controller.risks[j].description + '</div>');

                            var overlapping_flag = false;
                            var x_point = avarage_points_x[risk];
                            var y_point = avarage_points_y[risk];

                            //check if risks are overlapped
                            for (var risk_id in avarage_points_x) {

                                if (risk == risk_id) {
                                    continue;
                                }

                                var x_local_risk = avarage_points_x[risk_id];
                                var y_local_risk = avarage_points_y[risk_id];

                                if (x_point[0] == x_local_risk[0] &&
                                    y_point[0] == y_local_risk[0]) {
                                    overlapping_flag = true;
                                    break;
                                }//if
                            }//for

                            if (overlapping_flag) {

                                var controller_assessment;
                                for (var i = 0; i < controller.assessments.length; i++) {
                                    if (input_assessment.id == controller.assessments[i].id) {
                                        controller_assessment = controller.assessments[i];
                                        break;
                                    }
                                }

                                var tooltip_elements = '<div><form>';

                                //firefox fix for risks sequence
                                try {
                                    for (var k = 0; ; k++) {

                                        var risk_id = controller_assessment.risks[k];
                                        var x_local_risk = avarage_points_x[risk_id];
                                        var y_local_risk = avarage_points_y[risk_id];
                                        var id_displayed_risk = 'id_risk_' + controller_assessment.id + '_' + k;

                                        if (x_point[0] == x_local_risk[0] &&
                                            y_point[0] == y_local_risk[0]) {
                                            var risk_name = "";
                                            for (var i = 0; i < controller.risks.length; i++) {
                                                if (controller.risks[i].id == risk_id) {
                                                    risk_name = controller.risks[i].name;
                                                }
                                            }
                                            tooltip_elements = tooltip_elements + '<input type="button" value=' + risk_name +
                                                ' id = ' + id_displayed_risk + ' name = ' + risk_id + ' />' + ' <p>';

                                            $('#' + id_displayed_risk).live('click', function () {
                                                $('.result_chart_risk', panel_div).hide();
                                                view.display_participants_in_chart(input_assessment, parent_div_id, this.name, results_view_header_id);
                                            });
                                        }//if
                                    }//for
                                } catch (e) {
                                }

                                tooltip_elements = tooltip_elements + '</form></div>';
                                tooltip_div = $(tooltip_elements);
                            }

                            if (controller.user_agent == 'ipad') {

                            } else {
                                var offset = {
                                    x:-30,
                                    y:-40
                                };
                                lipstick.tooltip(new_risk_div, tooltip_div, offset);
                            }

                            break;
                        }//if correct risk found
                    }//find risk name for tooltip
                    if (!already_displayed) {
                        panel_div.append(new_risk_div);
                        new_risk_div.click(function () {
                            $('.result_chart_risk', panel_div).hide();
                            view.display_participants_in_chart(input_assessment, parent_div_id, this.id, results_view_header_id);
                        })
                    }
                }


                // for (var i = 0; i < iter_length; i++) {

                // //result of a risk aggregation
                // var position_y = 100 - (input_assessment.results[i].probability_value / controller.probability_levels.length * 100);
                // /*if (controller.host)
                // {
                // //position_y = 100 - (input_assessment.results[i].probability_value / controller.probability_levels.length) * 100;
                // }
                // else
                // {
                // position_y = 100 - (((input_assessment.results[i].probability_value / input_assessment.results[i].participant.length) / controller.probability_levels.length) * 100);
                // }*/
                // //position_y = 100 - (((input_assessment.results[i].probability_value / input_assessment.results[i].participant.length) / controller.probability_levels.length) * 100);

                // //var position_y = ((input_assessment.results[i].probability_value / controller.probability_levels.length) * 100);
                // var divider = 0;
                // for (var j = 0; j < controller.risks.length; j++) {
                // if (controller.risks[j].id == input_assessment.results[i].risk) {
                // for (var k in controller.risks[j].impacts) {
                // divider++;
                // }
                // }
                // }

                // var impact_value;
                // impact_value = input_assessment.results[i].impact_value / divider;
                // impact_value = impact_value / input_assessment.results[i].participant.length;
                // //impact_value = impact_value / input_assessment.results.length;
                // /*if (input_assessment.results[i].impact_value > controller.impact_levels.length){
                // impact_value = input_assessment.results[i].impact_value / divider;
                // } else{
                // impact_value = input_assessment.results[i].impact_value;
                // }
                // if (input_assessment.results[i].impact_value > controller.impact_levels.length){
                // impact_value = input_assessment.results[i].impact_value / input_assessment.results.length ;
                // }*/
                // //alert(impact_value);
                // var position_x = ((( impact_value/ controller.impact_levels.length) * 100) -5);
                // if(position_x < 0){
                // position_x = 0;
                // }
                // if(position_y > 90){
                // position_y = 90;
                // }

                // var new_risk_div = $('<div class="result_chart_risk" id="' + input_assessment.results[i].risk + '"' +
                // ' style="top:' + position_y + '%; ' + 'left:' + position_x + '%;"></div>');

                // for (var j = 0; j < controller.risks.length; j++) {
                // if (controller.risks[j].id == input_assessment.results[i].risk) {
                // var tooltip_div = $('<div width="50px">Name: ' + controller.risks[j].name + '</div>' +
                // '<div>Description: ' + controller.risks[j].description + '</div>');
                // if (controller.user_agent == 'ipad'){

                // } else{
                // var offset = {
                // x: -30,
                // y: -40
                // };
                // lipstick.tooltip(new_risk_div, tooltip_div, offset);
                // }
                // break;
                // }//if correct risk found
                // }//find risk name for tooltip
                // panel_div.append(new_risk_div);
                // new_risk_div.click(function() {
                // $('.result_chart_risk', panel_div).hide();
                // view.display_participants_in_chart(input_assessment, parent_div_id, this.id, results_view_header_id);
                // })//on risk clicked
                // //}
                // }//loop above all the assessment results
                $('#' + results_view_header_id).text("Overview");

            }, //display_risks_in_chart
            //------------------------------------------------ DISPLAY PATICIPANTS IN CHART ------------------------------------------------
            //     displays Participants in Chart
            //---------------------------------------------------------------------------------------------------------------------
            display_participants_in_chart:function (input_assessment, parent_div_id, risk_id, results_view_header_id) {
                var back_to_overview_id = elementId + '_back_to_overview_' + input_assessment.id;
                $('#' + back_to_overview_id).removeClass('switch_view').addClass('switch_view_show');
                var panel_div = $('#' + parent_div_id);
                for (var i = 0; i < input_assessment.results.length; i++) {
                    if (input_assessment.results[i].risk == risk_id) {

                        var risk = input_assessment.results[i];

                        for (var j = 0; j < risk.participant.length; j++) {
                            var position_y = 100 - ((risk.participant[j].probability_value / controller.probability_levels.length) * 100);
                            position_y += (100 / controller.probability_levels.length / 2) - 3;//display more accurately
                            var position_x = (((risk.participant[j].impact_value / controller.impact_levels.length) * 100));
                            position_x -= (100 / controller.impact_levels.length / 2) + 3; //display more accurately

                            if (position_x > 95) {
                                position_x = 95;
                            }
                            if (position_y < 0) {
                                position_y = 0;
                            }
                            var new_participant_div = $('<div class="result_chart_participant" id="' + risk.participant[j].id + '"' +
                                ' style="top:' +
                                position_y +
                                '%; ' +
                                'left:' +
                                position_x +
                                '%;"></div>');
                            panel_div.append(new_participant_div);
                            var tooltip_div = '';
                            if (controller.host) {
                                tooltip_div = $('<div class="item_tip_participant">' + risk.participant[j].id + '</div>')
                            }
                            else {
                                tooltip_div = $('<div class="item_tip_participant">' + com.streamwork.getParticipantById(risk.participant[j].id).displayName + '</div>')
                            }
                            if (controller.userAgent == 'ipad') {

                            }
                            else {
                                var offset = {
                                    x:-30,
                                    y:-40
                                }
                                lipstick.tooltip(new_participant_div, tooltip_div, offset);
                            }
                        }//display all participants
                    }//clicked risk found
                }//search for clicked risk
                for (i = 0; i < controller.risks.length; i++) {
                    if (controller.risks[i].id == risk_id) {
                        $('#' + results_view_header_id).text("Risk: " + controller.risks[i].name);
                        break;
                    }
                }
            }//display_participants_in_chart
        };//view
        controller = {

            host:null,
            first_load:null,
            user_agent:null,
            selected_aggreg_method:"Average",
            aggregation_methods:["Average", "Maximum"],
            config_locked:null,
            risks:[],
            assessments:[],
            impact_levels:[],
            probability_levels:[],
            residual_risk_levels:[],
            mitigation_effectiveness_levels:[],
            impact_categories:[],

            new_impact_levels:[],
            impact_levels_to_delete:[],
            impact_levels_to_change:[],
            impact_levels_to_create:[],

            new_probability_levels:[],
            probability_to_change:[],
            probability_to_delete:[],
            probability_to_create:[],

            new_mitigation_levels:[],
            mitigation_levels_to_delete:[],
            mitigation_levels_to_change:[],
            mitigation_levels_to_create:[],

            new_residual_levels:[],
            residual_levels_to_delete:[],
            residual_levels_to_change:[],
            residual_levels_to_create:[],

            org_units:[],
            risk_categories:[],

            selected_category_id:0,
            selected_org_unit_id:0,
            selected_impact_category:0,
            select_risks_to_use:null,
            callbacks_received:0,
            new_risk:{},
            start_assessment_risks:[],
            start_assessment:{},
            assessment_to_aggregate:[],
            aggregate_call_number:[],
            aggregate_call_counter:[],
            aggregate_risks:[],
            assessment_containers:[],
            start_assessment_number:0,
            start_assessment_counter:0,
            assessments_to_display:[],
            //----------------------------------------------- INIT ------------------------------------------------
            init:function () {
                controller.check_user_agent();
                if (initialData.first_load) {
                    controller.first_load = initialData.first_load;
                }
                //TODO
                if (initialData.backend) {
                    controller.host = initialData.backend;
                    controller.get_customizing();
                }
                //ADDITIONAL CODING BY D053422
                if (initialData.risk_table_header) {
                    view.risk_header_title_text = initialData.risk_table_header;
                }
                //END OF ADDITIONAL CODING
                view.show_main_view();
                view.div.resize(view._viewResizeHandler);
                //setTimeout();
                if (initialData.risks) {
                    for (var i = 0; i < initialData.risks.length; i++) {
                        var risk_opt = initialData.risks[i];
                        var risk = {
                            id:risk_opt.id,
                            name:risk_opt.value["name"],
                            category:risk_opt.value["category"],
                            category_id:risk_opt.value["category_id"],
                            description:risk_opt.value["description"],
                            org_unit:risk_opt.value["org_unit"],
                            org_unit_id:risk_opt.value["org_unit_id"],
                            impacts:risk_opt.value.impacts,
                            rm_assessment_id:risk_opt.value["rm_assessment_id"],
                            deleted:risk_opt.value["deleted"]
                        }
                        controller.risks.push(risk);
                        if (risk.deleted == false) {
                            view.show_created_risk(risk);
                        }
                    }//for
                }//risks
                if (initialData.aggregation_method) {
                    controller.selected_aggreg_method = initialData.aggregation_method;
                }
                else {
                    controller.selected_aggreg_method = "Average";
                }
                if (initialData.backend == "") {
                    if (initialData.impact_levels) {
                        for (var i = 0; i < initialData.impact_levels.length; i++) {
                            if (initialData.impact_levels[i].id) {
                                var impact_level = {
                                    value:initialData.impact_levels[i].value,
                                    text:initialData.impact_levels[i].text,
                                    id:initialData.impact_levels[i].id
                                }
                                if (typeof impact_level.value == "object") {
                                    impact_level = impact_level.value;
                                }
                                controller.impact_levels.push(impact_level);
                            }
                            else {
                                controller.impact_levels.push(initialData.impact_levels[i]);
                            }
                        }//for
                    }//impact_levels
                    if (initialData.probability_levels) {
                        for (var i = 0; i < initialData.probability_levels.length; i++) {
                            if (initialData.probability_levels[i].id) {
                                var probability_level = {
                                    value:initialData.probability_levels[i].value,
                                    text:initialData.probability_levels[i].text,
                                    id:initialData.probability_levels[i].id
                                }
                                if (typeof probability_level.value == "object") {
                                    probability_level = probability_level.value;
                                }
                                controller.probability_levels.push(probability_level);
                            }
                            else {
                                controller.probability_levels.push(initialData.probability_levels[i]);
                            }
                        }//for
                    }
                }

                //ADDITIONAL CODING BY D053422
                if (initialData.residual_risk_levels) {
                    for (var i = 0; i < initialData.residual_risk_levels.length; i++) {
                        if (initialData.residual_risk_levels[i].id) {
                            var residual_risk_level = {
                                value:initialData.residual_risk_levels[i].value,
                                text:initialData.residual_risk_levels[i].text,
                                id:initialData.residual_risk_levels[i].id
                            }
                            if (typeof residual_risk_level.value == "object") {
                                residual_risk_level = residual_risk_level.value;
                            }
                            controller.residual_risk_levels.push(residual_risk_level);
                        }
                        else {
                            controller.residual_risk_levels.push(initialData.residual_risk_levels[i]);
                        }
                    }//for
                }

                if (initialData.mitigation_effectiveness_levels) {
                    for (var i = 0; i < initialData.mitigation_effectiveness_levels.length; i++) {
                        if (initialData.mitigation_effectiveness_levels[i].id) {
                            var mitigation_effectiveness_level = {
                                value:initialData.mitigation_effectiveness_levels[i].value,
                                text:initialData.mitigation_effectiveness_levels[i].text,
                                id:initialData.mitigation_effectiveness_levels[i].id
                            }
                            if (typeof mitigation_effectiveness_level.value == "object") {
                                mitigation_effectiveness_level = mitigation_effectiveness_level.value;
                            }
                            controller.mitigation_effectiveness_levels.push(mitigation_effectiveness_level);
                        }
                        else {
                            controller.mitigation_effectiveness_levels.push(initialData.mitigation_effectiveness_levels[i]);
                        }
                    }//for
                }
                //END OF ADDITIONAL CODING

                if (initialData.assessments) {
                    for (var i = 0; i < initialData.assessments.length; i++) {
                        var assessment_opt = initialData.assessments[i];
                        var index = assessment_opt.id.indexOf("_");
                        index = assessment_opt.id.indexOf("_", index + 1);
                        index = assessment_opt.id.indexOf("_", index + 1);
                        index = assessment_opt.id.indexOf("_", index + 1);
                        index = assessment_opt.id.indexOf("_", index + 1);
                        var id = assessment_opt.id.substring(index + 1);
                        var assessment = {
                            id:assessment_opt.id,
                            name:assessment_opt.value["name"],
                            deleted:assessment_opt.value["deleted"],
                            status:assessment_opt.value["status"],
                            start_date:assessment_opt.value["start_date"],
                            due_date:assessment_opt.value["due_date"],
                            risks:assessment_opt.value["risks"],
                            results:assessment_opt.value["results"],
                            owner:assessment_opt.value["owner"],
                            assess_map:assessment_opt.value["assess_map"],
                            edited_by:assessment_opt.value["edited_by"]
                        }
                        controller.assessments.push(assessment);

                        //for status in planning show only assessments for owner
                        if (assessment.owner != streamwork.getViewerId() && assessment.status == 'in planning') {
                            continue;
                        }

                        if (initialData.backend == "")//null)
                        {
                            view.create_new_assessment(id, assessment);
                        }
                        else {
                            controller.assessments_to_display.push({'id':id, 'assessment':assessment});
                            //view.create_new_assessment(id, assessment);
                        }
                        //controller.assessments_to_display.push({'id': id, 'assessment': assessment});
                        //view.create_new_assessment(id, assessment);
                        //, assessment.value["collapsed"]
                    }//for
                    controller.assessment_check();
                }//assessment
                if (initialData.assessment_containers && initialData.backend == "") {
                    for (var i = 0; i < initialData.assessment_containers.length; i++) {
                        controller.assessment_containers.push(initialData.assessment_containers[i]);
                    }//for
                }//assessment container
                controller.config_locked = initialData.config_locked;
                if (initialData.backend == "") {
                    for (var i = 0; i < controller.assessment_containers.length; i++) {
                        var assessment_container = controller.assessment_containers[i];
                        if (assessment_container.value["visible"] == false) {
                            view.hide_new_assessment(assessment_container.id, assessment_container.value["arrow"], false, assessment_container.value["assessment_name_id"]);
                        }//visibile false
                    }
                }
                //console.log("init method completed");
                view._viewResizeHandler();
                return controller; //return controller;
            }, //init

            check_for_assessment_view:function () {
                controller.callbacks_received++;
                if (controller.callbacks_received == 5) {
                    controller.callbacks_received = 0;
                    //for (var i = 0; i < controller.assessments.length; i++) {
                    //   view.create_new_assessment(controller.assessments[i].id, controller.assessments[i]);
                    //}
                    if (initialData.assessments) {
                        /*for (var i = 0; i < initialData.assessment_containers.length; i++) {
                         controller.assessment_containers.push(initialData.assessment_containers[i]);
                         }//for
                         for (var i = 0; i < controller.assessment_containers.length; i++){
                         var assessment_container = controller.assessment_containers[i];
                         if (assessment_container.value["visible"] == false) {
                         view.hide_new_assessment(assessment_container.id, assessment_container.value["arrow"], false, assessment_container.value["assessment_name_id"]);
                         }//visibile false
                         }*/
                        for (var i = 0; i < initialData.assessments.length; i++) {
                            var assessment = initialData.assessments[i];
                            if (assessment.value["owner"] == streamwork.getViewerId() || assessment.value["status"] != 'in planning') {
                                view.create_new_assessment(assessment.id, assessment.value);
                            }
                        }


                    }

                    lipstick.removeWaitOverlay(view.loading_target);
                }
            },

            publish:function (title, options) {
                //view.div.data('title', title);
                //view.div.data('options', options);
                //view.div.data('published', true);

                // send to server
                proxy.publish(title, options);
                return true;
            }, //publish
            check_user_agent:function () {
                var agent = navigator.userAgent.toLowerCase();
                if (agent.indexOf("msie") > -1) {
                    controller.user_agent = "msie";
                    //alert("MSIE");
                    return;
                }
                if (agent.indexOf("safari") > -1) {
                    controller.user_agent = "safari";
                    //alert("Safari");
                }
                if (agent.indexOf("ipad") > -1) {
                    controller.user_agent = "ipad";
                    return;
                }
                controller.user_agent = "other";
                //alert("other");
            },

            org_units_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    controller.check_for_assessment_view();
                } else {
                    controller.org_units = data;
                    controller.check_for_assessment_view();

                    var request_type = "";
                    request_type = 'jsonp';

                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }
                    streamwork._risk_categories_callback = controller.risk_categories_callback;
                    $.ajax({
                        url:'http://' + controller.host + '/sap/resources/risk_categories?streamwork._risk_categories_callback=callback',
                        type:'GET',
                        dataType:request_type,
                        jsonp:streamwork._risk_categories_callback,
                        contentType:'application/json'
                    });
                }
            },

            risk_categories_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    controller.check_for_assessment_view();
                } else {
                    controller.risk_categories = data;
                    controller.check_for_assessment_view();

                    var request_type = "";
                    request_type = 'jsonp';
                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }

                    streamwork._impact_levels_callback = controller.impact_levels_callback;
                    $.ajax({
                        url:'http://' + controller.host + '/sap/resources/impact_levels?streamwork._impact_levels_callback=callback',
                        type:'GET',
                        dataType:request_type,
                        jsonp:streamwork._impact_levels_callback,
                        contentType:'application/json'
                    });
                }
            },

            impact_levels_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    controller.check_for_assessment_view();
                } else {
                    controller.impact_levels = data;
                    controller.check_for_assessment_view();

                    var request_type = "";
                    request_type = 'jsonp';
                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }

                    streamwork._prob_levels_callback = controller.prob_levels_callback;
                    $.ajax({
                        url:'http://' + controller.host + '/sap/resources/prob_levels?streamwork._prob_levels_callback=callback',
                        type:'GET',
                        dataType:request_type,
                        jsonp:streamwork._prob_levels_callback,
                        contentType:'application/json'
                    });
                }
            },

            prob_levels_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    controller.check_for_assessment_view();
                } else {
                    controller.probability_levels = data;
                    controller.check_for_assessment_view();

                    var request_type = "";
                    request_type = 'jsonp';
                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }

                    streamwork._impact_categories_callback = controller.impact_categories_callback;
                    $.ajax({
                        url:'http://' + controller.host + '/sap/resources/impact_categories?streamwork._impact_categories_callback=callback',
                        type:'GET',
                        dataType:request_type,
                        jsonp:streamwork._impact_categories_callback,
                        contentType:'application/json'
                    });
                }
            },

            impact_categories_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    controller.check_for_assessment_view();
                }
                else {
                    lipstick.removeWaitOverlay(view.loading_target);
                    controller.impact_categories = data;
                    controller.check_for_assessment_view();
                }
            },
            craete_risk_callback:function (data, error_msg) {
                //alert('received');
                if (error_msg) {
                    lipstick.alert(error_msg);
                    lipstick.removeWaitOverlay(view.loading_target);
                }
                else {
                    /*var options = {
                     id: data,
                     value: {
                     name: controller.new_risk.name,
                     category: controller.new_risk.category,
                     description: controller.new_risk.description,
                     org_unit: controller.new_risk.org_unit,
                     impacts: controller.new_risk.impacts,
                     rm_assessment_id: controller.new_risk.rm_assessment_id,
                     deleted: controller.new_risk.deleted
                     }
                     };
                     impacts_array = [];
                     controller.new_risk = {};
                     proxy.create_risk(options);*/
                    /*var impacts_array = controller.new_risk.impacts;
                     var impacts = {};
                     var risk_id = generate_id();
                     for (var i = 0; i < impacts_array.length; i++) {
                     impacts[i] = impacts_array[i];
                     }*/
                    var options = {
                        id:data,
                        value:controller.new_risk
                    }

                    proxy.create_risk(options);

                }
            },

            submit_to_rm_callback:function (data) {
                lipstick.removeWaitOverlay(view.loading_target);
            },
            //TODO
            //--------------------------------------------- GET SYSTEM CUSTOMIZING ----------------------------------------
            get_customizing:function () {
                //'http://coevi131.wdf.sap.corp:8000/sap/zsw_trigger_act?sap-client=800',
                //alert("get customizing");

                var request_type = "";
                //if (controller.user_agent == "safari"){
                request_type = 'jsonp';
                //}
                //else{
                //    request_type = 'json';
                //}
                try {
                    if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                        //console.log("PRIV SETTING");
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                    }
                }
                catch (e) {
                    //alert("(Mozilla) - " + e);
                }
                view.loading_target = view.div;
                lipstick.addWaitOverlay(view.loading_target);
                streamwork._org_units_callback = controller.org_units_callback;
                $.ajax({
                    url:'http://' + controller.host + '/sap/resources/orgs_units?streamwork._org_units_callback=callback',
                    type:'GET',
                    //context        : this,
                    //cache        : false,
                    //async        : false,
                    dataType:request_type,
                    jsonp:streamwork._org_units_callback,
                    //crossDomain : true,
                    contentType:'application/json'
                });

                /*streamwork._risk_categories_callback = controller.risk_categories_callback;
                 $.ajax({
                 url: 'http://' + controller.host + '/sap/resources/risk_categories',
                 type        : 'GET',
                 //context        : this,
                 //cache        : false,
                 //async        : false,
                 dataType    : request_type,
                 jsonp        : streamwork._risk_categories_callback,
                 //crossDomain : true,
                 contentType    : 'application/json'
                 });
                 streamwork._impact_levels_callback = controller.impact_levels_callback;
                 $.ajax({
                 url: 'http://' + controller.host + '/sap/resources/impact_levels',
                 type        : 'GET',
                 //context        : this,
                 //cache        : false,
                 //async        : false,
                 dataType    : request_type,
                 jsonp        : streamwork._impact_levels_callback,
                 //crossDomain : true,
                 contentType    : 'application/json'
                 });
                 streamwork._prob_levels_callback = controller.prob_levels_callback;
                 $.ajax({
                 url: 'http://' + controller.host + '/sap/resources/prob_levels',
                 type        : 'GET',
                 //context        : this,
                 //cache        : false,
                 //async        : false,
                 dataType    : request_type,
                 jsonp        : streamwork._prob_levels_callback,
                 //crossDomain : true,
                 contentType    : 'application/json'
                 });
                 streamwork._impact_categories_callback = controller.impact_categories_callback;
                 $.ajax({
                 url: 'http://' + controller.host + '/sap/resources/impact_categories',
                 type        : 'GET',
                 //context        : this,
                 //cache        : false,
                 //async        : false,
                 dataType    : request_type,
                 jsonp        : streamwork._impact_categories_callback,
                 //crossDomain : true,
                 contentType    : 'application/json'
                 });*/
            },

            //--------------------------------------------- SET CONFIG LOCKED ----------------------------------------
            set_config_locked:function () {
                var options = true;
                proxy.set_configuration_lock(options);
            }, //toogle_config_lock
            //--------------------------------------------- SET CONFIG LOCKED ----------------------------------------
            set_config_unlocked:function () {
                var options = false;
                proxy.set_configuration_lock(options);
            }, //toogle_config_lock
            //--------------------------------------------- GET CONFIG LOCKED ----------------------------------------
            get_configuration_locked:function () {
                proxy.get_configuration_lock();
            }, //get_config_lock
            //--------------------------------------------- CLONE -------------------------------------------------------
            clone:function (array) {
                var new_array = [];
                for (var i = 0; i < array.length; i++) {
                    new_array[i] = controller.clone_obj(array[i]);
                }
                return new_array;
            },

            clone_obj:function (obj) {
                var new_obj = {}
                for (var i in obj) {
                    new_obj[i] = obj[i];
                }
                return new_obj;
            },

            //--------------------------------------------- REMOVE IMPACT -------------------------------------------------
            remove_impact:function (index, id) {
                var deleted = false;
                var new_impact_level_list = [];
                for (var i = 0; i < controller.new_impact_levels.length; i++) {
                    if (i != (index - 1)) {
                        if (deleted == true) {
                            var impact = controller.new_impact_levels[i];
                            impact.value = impact.value - 1;
                            new_impact_level_list.push(impact);
                            //controller.update_impact_level(impact);
                        }
                        else {
                            new_impact_level_list.push(controller.new_impact_levels[i]);
                        }
                    }
                    else {
                        //proxy.delete_impact_level(id);
                        controller.impact_levels_to_delete.push(id);
                        deleted = true;
                    }
                }//for
                //new_impact_level_list.reverse();
                controller.new_impact_levels = new_impact_level_list;
            }, //remove impact
            //--------------------------------------------- COMMIT IMPACT LEVELS -------------------------------------------------
            commit_impact_levels:function () {
                for (var i = 0; i < controller.impact_levels_to_change.length; i++) {
                    controller.update_impact_level(controller.impact_levels_to_change[i]);
                }//all impact levels to change
                for (var i = 0; i < controller.impact_levels_to_delete.length; i++) {
                    proxy.delete_impact_level(controller.impact_levels_to_delete[i]);
                }//all impact level to delete
                for (var i = 0; i < controller.impact_levels_to_create.length; i++) {
                    controller.create_impact_level(controller.impact_levels_to_create[i]);
                }//all impact level to create
                controller.impact_levels_to_delete = [];
                controller.impact_levels_to_create = [];
                controller.impact_levels_to_change = [];
                controller.impact_levels = controller.clone(controller.new_impact_levels);
            }, //commit_impact_levels
            //--------------------------------------------- REMOVE PROBABILITY --------------------------------------------
            remove_probability:function (index, id) {
                var deleted = false;
                var new_prob_level_list = [];
                for (var i = 0; i < controller.new_probability_levels.length; i++) {
                    if (i != (index - 1)) {
                        if (deleted == true) {
                            var probability = controller.new_probability_levels[i];
                            probability.value = probability.value - 1;
                            new_prob_level_list.push(probability);
                            //controller.update_probability_level(probability);
                        }
                        else {
                            new_prob_level_list.push(controller.new_probability_levels[i]);
                        }
                    }
                    else {
                        //proxy.delete_probability_level(id);
                        controller.probability_to_delete.push(id);
                        deleted = true;
                    }
                }//for
                //new_impact_level_list.reverse();
                controller.new_probability_levels = new_prob_level_list;
            }, //remove probability
            //--------------------------------------------- COMMIT PROBABILITY LEVELS -------------------------------------------------
            commit_probability_levels:function () {
                for (var i = 0; i < controller.probability_to_change; i++) {
                    controller.update_probability_level(controller.probability_to_change[i]);
                }//all probability levels to change
                for (var i = 0; i < controller.probability_to_delete.length; i++) {
                    proxy.delete_probability_level(controller.probability_to_delete[i]);
                }//all probability levels to delete
                for (var i = 0; i < controller.probability_to_create; i++) {
                    controller.create_probability_level(controller.probability_to_create[i]);
                }//all probability levels to create
                controller.probability_to_change = [];
                controller.probability_to_delete = [];
                controller.probability_to_create = [];
                controller.probability_levels = controller.clone(controller.new_probability_levels);
            }, //commit_impact_levels

            //ADDITIONAL CODING BY D053422
            //--------------------------------------------- REMOVE MITIGATION-----------------------------------------------
            remove_mitigation:function (index, id) {
                var deleted = false;
                var new_mitigation_level_list = [];
                for (var i = 0; i < controller.new_mitigation_levels.length; i++) {
                    if (i != (index - 1)) {
                        if (deleted == true) {
                            var impact = controller.new_mitigation_levels[i];
                            impact.value = impact.value - 1;
                            new_mitigation_level_list.push(impact);
                            //controller.update_impact_level(impact);
                        }
                        else {
                            new_mitigation_level_list.push(controller.new_mitigation_levels[i]);
                        }
                    }
                    else {
                        //proxy.delete_impact_level(id);
                        controller.mitigation_levels_to_delete.push(id);
                        deleted = true;
                    }
                }//for
                //new_impact_level_list.reverse();
                controller.new_mitigation_levels = new_mitigation_level_list;
            }, //remove mitigation
            //--------------------------------------------- COMMIT MITIGATION LEVELS -------------------------------------------------
            commit_mitigation_levels:function () {
                for (var i = 0; i < controller.mitigation_levels_to_change.length; i++) {
                    controller.update_mitigation_level(controller.mitigation_levels_to_change[i]);
                }//all impact levels to change
                for (var i = 0; i < controller.mitigation_levels_to_delete.length; i++) {
                    proxy.delete_mitigation_level(controller.mitigation_levels_to_delete[i]);
                }//all impact level to delete
                for (var i = 0; i < controller.mitigation_levels_to_create.length; i++) {
                    controller.create_mitigation_level(controller.mitigation_levels_to_create[i]);
                }//all impact level to create
                controller.mitigation_levels_to_delete = [];
                controller.mitigation_levels_to_create = [];
                controller.mitigation_levels_to_change = [];
                controller.mitigation_effectiveness_levels = controller.clone(controller.new_mitigation_levels);
            }, //commit_mitigation_levels

            //--------------------------------------------- REMOVE RESIDUAL-----------------------------------------------
            remove_residual:function (index, id) {
                var deleted = false;
                var new_residual_level_list = [];
                for (var i = 0; i < controller.new_residual_levels.length; i++) {
                    if (i != (index - 1)) {
                        if (deleted == true) {
                            var residual = controller.new_residual_levels[i];
                            residual.value = residual.value - 1;
                            new_residual_level_list.push(residual);
                            //controller.update_impact_level(impact);
                        }
                        else {
                            new_residual_level_list.push(controller.new_residual_levels[i]);
                        }
                    }
                    else {
                        //proxy.delete_impact_level(id);
                        controller.residual_levels_to_delete.push(id);
                        deleted = true;
                    }
                }//for
                //new_impact_level_list.reverse();
                controller.new_residual_levels = new_residual_level_list;
            }, //remove residual
            //--------------------------------------------- COMMIT RESIDUAL LEVELS -------------------------------------------------
            commit_residual_levels:function () {
                for (var i = 0; i < controller.residual_levels_to_change.length; i++) {
                    controller.update_residual_level(controller.residual_levels_to_change[i]); //TODO
                }//all impact levels to change
                for (var i = 0; i < controller.residual_levels_to_delete.length; i++) {
                    proxy.delete_residual_level(controller.residual_levels_to_delete[i]); //TODO
                }//all impact level to delete
                for (var i = 0; i < controller.residual_levels_to_create.length; i++) {
                    controller.create_residual_level(controller.residual_levels_to_create[i]); //TODO
                }//all impact level to create
                controller.residual_levels_to_delete = [];
                controller.residual_levels_to_create = [];
                controller.residual_levels_to_change = [];
                controller.residual_risk_levels = controller.clone(controller.new_residual_levels);
            }, //commit_residual_levels
            //END OF ADDITIONAL CODING

            //-------------------------------------------- AGGREGATE RESTULTS CALLBACK ----------------------------------------------
            aggregate_assessment_callback:function (data) {

                var risk_array = [];
                var risk_data;
                //get the risk from the data
                for (var i = 0; i < controller.risks.length; i++) {
                    if (controller.risks[i].rm_assessment_id == data.risk) {
                        risk_data = controller.risks[i].id;
                        break;
                    }
                }
                for (var i = 0; i < controller.assessment_to_aggregate.length; i++) {
                    if (data.assessment == controller.assessment_to_aggregate[i].id) {
                        risk_array = controller.aggregate_risks[data.assessment];
                        //data.risk = risk_array[controller.aggregate_call_counter[i]];
                        data.risk = risk_data;
                        controller.aggregate_call_counter[i]++;
                        controller.assessment_to_aggregate[i].results.push(data);
                        /*if (controller.aggregate_call_counter[i] == controller.aggregate_call_number[i]) {
                         controller.aggregate_call_number[i] = 0;
                         controller.aggregate_call_counter[i] = 0;*/
                        view.show_assessment_results(controller.assessment_to_aggregate[i].id, controller.assessment_to_aggregate[i]);
                        //controller.assessment_to_aggregate[i] = {};
                        //controller.aggregate_risks = [];
                        lipstick.removeWaitOverlay(view.loading_target);
                        //}
                    }
                }

            },

            //-------------------------------------------- AGGREGATE RESTULTS ----------------------------------------------
            aggregate_results:function (input_assessment) {
                var assessment = input_assessment;

                if (controller.host != null) {
                    view.loading_target = view.div;
                    lipstick.addWaitOverlay(view.loading_target);
                    controller.assessment_to_aggregate.push(input_assessment);
                    streamwork._aggregate_assessment_callback = controller.aggregate_assessment_callback;
                    controller.aggregate_call_number.push(input_assessment.risks.length)
                    controller.aggregate_call_counter.push(0);
                    controller.aggregate_risks[input_assessment.id] = [];
                    for (var i = 0; i < input_assessment.risks.length; i++) {
                        //                    for(var i in input_assessment.risks){
                        var risk_id = input_assessment.risks[i];
                        var risk = null;
                        for (var j = 0; j < controller.risks.length; j++) {
                            if (risk_id == controller.risks[j].id) {
                                risk = controller.risks[j];
                                break;
                            }
                        }
                        var assessmentRMid = risk.rm_assessment_id;
                        try {
                            if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                                //console.log("PRIV SETTING");
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                            }
                        }
                        catch (e) {
                            //alert("(Mozilla) - " + e);
                        }
                        var assessmentObjectRM = {
                            assessment_id:assessmentRMid,
                            assessment:input_assessment.id
                        };
                        controller.aggregate_risks[input_assessment.id].push(risk_id);
                        var jsonString = JSON.stringify(assessmentObjectRM);
                        $.ajax({
                            url:'http://' + controller.host + '/sap/resources/assessment/calc/_' + jsonString,
                            type:'GET',
                            dataType:'jsonp',
                            jsonp:'streamwork._aggregate_assessment_callback',
                            data:jsonString,
                            async:false,
                            success:function (data) {
                                data.risk = risk_id;
                                assessment.results.push(data);
                                //alert(data);
                            },
                            error:function (data) {
                                //alert("error");
                            }
                        });
                    }
                }
                else {
                    var aggregated_mitigation_vote = 0;
                    var aggregated_residual_risk_vote = 0;
                    for (var i = 0; i < input_assessment.assess_map.length; i++) {
                        var assess_map_entry = input_assessment.assess_map[i];
                        var person_assessed_risks = [];
                        aggregated_mitigation_vote = controller.run_aggregation_method(aggregated_mitigation_vote,
                            assess_map_entry.mitigation_effectiveness_vote);
                        aggregated_residual_risk_vote = controller.run_aggregation_method(aggregated_residual_risk_vote,
                            assess_map_entry.residual_risk_vote);
                        for (var j = 0; j < assess_map_entry.risks.length; j++) {
                            var assessed_risk = assess_map_entry.risks[j];
                            var aggregated_impacts = 0;

                            //pretty_alert('assessed_risk:\n', assessed_risk);
                            for (var k = 0; k < assessed_risk.impact_votes.length; k++) {
                                aggregated_impacts = controller.run_aggregation_method(aggregated_impacts,
                                    assessed_risk.impact_votes[k].value);
                            }//all impacts of one risk
                            //aggregated_impacts = aggregated_impacts / assessed_risk.impact_votes.length;
                            var participant = {
                                id:assess_map_entry.user,
                                impact_value:aggregated_impacts,
                                probability_value:assessed_risk.probability
                            }
                            var entry = {
                                risk:assessed_risk.id,
                                impact_value:aggregated_impacts,
                                probability_value:assessed_risk.probability,
                                participant:[]
                            }
                            entry.participant.push(participant);
                            person_assessed_risks.push(entry);
                        }//loop above assessed risks by one person

                        for (j = 0; j < person_assessed_risks.length; j++) {
                            if (assessment.results.length == 0) {
                                assessment.results.push(person_assessed_risks[j]);
                            }//if no risk result exist
                            else {
                                var exists;
                                var n_results = assessment.results.length;
                                for (k = 0; k < n_results; k++)//for (k = 0; k < assessment.results.length; k++)
                                {
                                    exists = false;

                                    if (assessment.results[k].risk == person_assessed_risks[j].risk) {
                                        assessment.results[k].impact_value = assessment.results[k].impact_value + person_assessed_risks[j].impact_value;
                                        assessment.results[k].participant.push(person_assessed_risks[j].participant[0]);
                                        exists = true;
                                        break;
                                    }//if there is already a entry for this risk modify this entry
                                }

                                if (exists == false) {
                                    assessment.results.push(person_assessed_risks[j]);
                                }
                            }
                        }// each risk one person assessed must be added
                    }//loop above all assess_entries
                    aggregated_mitigation_vote = aggregated_mitigation_vote / input_assessment.assess_map.length;
                    aggregated_residual_risk_vote = aggregated_residual_risk_vote / input_assessment.assess_map.length;
                    var additionalEntry = {
                        mitigation_value:aggregated_mitigation_vote,
                        mitigation_max_value:controller.mitigation_effectiveness_levels.length,
                        residual_value:aggregated_residual_risk_vote,
                        residual_max_value:controller.residual_risk_levels.length
                    };
                    assessment.results.push(additionalEntry);
                }

                //added by C5163319

                for (var i = 0; i < assessment.results.length; i++) {
                    var probability_sum = 0;
                    if (assessment.results[i].participant) {
                        for (var j = 0; j < assessment.results[i].participant.length; j++) {
                            //alert('probability_value=' + assessment.results[i].participant[j].probability_value);
                            probability_sum += parseInt(assessment.results[i].participant[j].probability_value);
                        }

                        assessment.results[i].probability_value = probability_sum / assessment.results[i].participant.length;
                    }
                }//end added by C5163319

            }, //aggregate_results
            //-------------------------------------------- AGGREGATE RESTULTS ----------------------------------------------
            run_aggregation_method:function (basis, new_value) {
                if (controller.selected_aggreg_method == "Average") {
                    return (basis - -new_value);
                }//average
                if (controller.selected_aggreg_method == "Maximum") {
                    if (basis < new_value) {
                        return new_value;
                    }//
                    if (new_value < basis) {
                        return basis;
                    }//
                }//maximum
            }, //aggregate_results
            //-------------------------------------------- UPDATE SELECTED AGGREGATION METHOD ----------------------------------------------
            update_selected_aggregation_method:function (method) {
                var options = {
                    value:method
                }
                proxy.update_selected_aggregation_method(options);
            },

            //-------------------------------------------- CREATE ASSESSMENT CONTAINER ----------------------------------------------
            create_assessment_container:function (id, value, arrow, assessment_name_id) {
                //console.log("Create Assessment Container...");
                var assessment = {
                    id:id,
                    value:{
                        visible:value,
                        arrow:arrow,
                        assessment_name_id:assessment_name_id
                    }
                }
                proxy.create_assessment_container(assessment);
            }, //create_assessment_container
            //-------------------------------------------- UPDATE ASSESSMENT CONTAINER ----------------------------------------------
            update_assessment_container:function (id, value, arrow) {
                //console.log("Update Assessment Container...");
                var assessment = {
                    id:id,
                    value:{
                        visible:value,
                        arrow:arrow
                    }
                }
                proxy.update_assessment_container(assessment);
            }, //update_assessment_container
            //-------------------------------------------- CREATE ASSESSMENT ----------------------------------------------
            create_assessment:function (assessment_input) {
                //console.log("Create Assessment...");
                var risks_array = assessment_input.risks, risks = {};
                for (var i = 0; i < risks_array.length; i++) {
                    risks[i] = risks_array[i];
                }
                var assessment = {
                    id:assessment_input.id,
                    value:{
                        name:assessment_input.name,
                        start_date:assessment_input.start_date,
                        due_date:assessment_input.due_date,
                        deleted:assessment_input.deleted,
                        status:assessment_input.status,
                        risks:risks,
                        results:assessment_input.results,
                        owner:assessment_input.owner,
                        assess_map:assessment_input.assess_map
                    }
                }

                proxy.create_assessment(assessment);
            }, //create_assessment

            get_assessment_for_close:function (assessment_id) {
                proxy.get_assessment_for_close(assessment_id);
            },
            //--------------------------------------------- UPDATE ASSESSMENT ---------------------------------------------
            update_assessment:function (assessment_input) {
                //console.log("Update Assessment...");
                var risks = {};
                var risks_array = assessment_input.risks;
                if (risks_array.length == undefined) {
                    risks = risks_array;
                }
                else {
                    for (var i = 0; i < risks_array.length; i++) {
                        risks[i] = risks_array[i];
                    }//for
                }
                var assessment = {
                    id:assessment_input.id,
                    value:{
                        name:assessment_input.name,
                        start_date:assessment_input.start_date,
                        due_date:assessment_input.due_date,
                        deleted:assessment_input.deleted,
                        status:assessment_input.status,
                        risks:risks,
                        results:assessment_input.results,
                        owner:assessment_input.owner,
                        assess_map:assessment_input.assess_map,
                        edited_by:assessment_input.edited_by
                    }
                }

                proxy.update_assessment(assessment);
            }, //create_assessment

            //----------------------------------------------- START ASSESSMENT: CALLBACK ------------------------------------------------
            start_assessment_callback:function (data, error_msg) {
                if (error_msg) {
                    lipstick.alert(error_msg);
                    lipstick.removeWaitOverlay(view.loading_target);
                }
                else {
                    $('#' + controller.start_assessment.assessment_collapse_id).hide();
                    $('#' + controller.start_assessment.assessment_status_id).text("running");
                    //view.loading_target = new_assessment_div;
                    controller.update_assessment(controller.start_assessment.assessment);

                    for (var j = 0; j < controller.risks.length; j++) {
                        if (controller.risks[j].id == data.risk_id) {
                            var risk_to_change = controller.risks[j];
                            risk_to_change.rm_assessment_id = data.assessment_id;
                            controller.risks[j] = risk_to_change;
                            controller.update_risk(risk_to_change);
                            break;
                        }
                    }
                    controller.start_assessment_counter++;

                }
                if (controller.start_assessment_number == controller.start_assessment_counter) {
                    view.run_assessment(controller.start_assessment.assessment.id, controller.start_assessment.assessment);
                    controller.start_assessment_number = 0;
                    controller.start_assessment_counter = 0;
                    controller.start_assessment_risks = [];
                    lipstick.removeWaitOverlay(view.loading_target);
                }
            },

            //----------------------------------------------- START ASSESSMENT ------------------------------------------------
            start_risk_assessment:function (assessment) {
                if (controller.host != null) {
                    view.loading_target = view.div;
                    lipstick.addWaitOverlay(view.loading_target);
                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }
                    streamwork._start_assessment_callback = controller.start_assessment_callback;

                    var risks_array = assessment.risks;
                    controller.start_assessment_number = risks_array.length;
                    for (var i = 0; i < risks_array.length; i++) {
                        //var risk_for_rm = risks_array[0];
                        var assessmentObjectRM = {
                            risk_id:risks_array[i]
                        }
                        if (!controller.start_assessment_risks) {
                            controller.start_assessment_risks = [];
                        }
                        controller.start_assessment_risks.push(assessmentObjectRM);
                        jsonString = JSON.stringify(assessmentObjectRM);
                        $.ajax({
                            url:'http://' + controller.host + '/sap/resources/assessment/_' + jsonString,
                            type:'GET',
                            dataType:'jsonp',
                            jsonp:'streamwork._start_assessment_callback',
                            data:jsonString,
                            async:false,
                            success:function (data) {
                                //alert("success");
                            },
                            error:function (data) {
                                //alert("error");
                            }
                        });
                    }
                }//if backend connection exists
            }, //start_assessment

            //----------------------------------------------- SUBMIT TO RM ------------------------------------------------
            submit_to_rm:function (assess_map_entry) {
                var parent_id;
                view.loading_target = view.div;
                lipstick.addWaitOverlay(view.loading_target);
                //TODO
                try {
                    if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                        //console.log("PRIV SETTING");
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                    }
                }
                catch (e) {
                    //alert("(Mozilla) - " + e);
                }
                if (controller.host != null) {

                    for (var i = 0; i < assess_map_entry.risks.length; i++) {
                        var risk_entry = assess_map_entry.risks[i];
                        var user = streamwork.getParticipantById(assess_map_entry.user);
                        var assessmentObjectRM = {
                            parent_id:"",
                            participant:user.getDisplayName(),
                            assessment:[]
                        }
                        for (var j = 0; j < risk_entry.impact_votes.length; j++) {

                            assessmentObjectRM.assessment.push({
                                probability:risk_entry.probability,
                                impact_name:risk_entry.impact_votes[j].name,
                                impact:risk_entry.impact_votes[j].value
                            });
                        }
                        for (var j = 0; j < controller.risks.length; j++) {
                            if (controller.risks[j].id == risk_entry.id) {
                                assessmentObjectRM.parent_id = controller.risks[j].rm_assessment_id;
                                //alert("parent id set to " + parent_id);
                                break;
                            }
                        }

                        streamwork._submit_to_rm_callback = controller.submit_to_rm_callback;
                        jsonString = JSON.stringify(assessmentObjectRM);
                        $.ajax({
                            url:'http://' + controller.host + '/sap/resources/assessment/participant/_' + jsonString,
                            type:'GET',
                            dataType:'jsonp',
                            jsonp:'streamwork._submit_to_rm_callback',
                            data:jsonString,
                            async:false,
                            success:function (data) {
                            },
                            error:function (data) {
                                //alert("error");
                            }
                        });
                    }
                }
            }, //submit_to_rm

            //----------------------------------------------- CREATE RISK ------------------------------------------------
            create_risk:function (risk) {
                //console.log("Create Risk...");
                view.loading_target = view.div;
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var impacts_array = risk.impacts;
                var impacts = {};
                var risk_id = generate_id();
                for (var i = 0; i < impacts_array.length; i++) {
                    impacts[i] = impacts_array[i];
                }
                var risk_for_db = {
                    name:risk.name,
                    category:risk.category,
                    category_id:risk.category_id,
                    description:risk.description,
                    org_unit:risk.org_unit,
                    org_unit_id:risk.org_unit_id,
                    impacts:impacts,
                    rm_assessment_id:risk.rm_assessment_id,
                    deleted:risk.deleted
                }

                if (controller.host != null) {
                    controller.new_risk = risk_for_db;
                    try {
                        if (!document.all && netscape.security.PrivilegeManager.enablePrivilege) {
                            //console.log("PRIV SETTING");
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                        }
                    }
                    catch (e) {
                        //alert("(Mozilla) - " + e);
                    }
                    var riskObjectRM = {
                        name:risk.name,
                        category:risk.category_id,
                        description:risk.description,
                        org_unit:risk.org_unit_id,
                        impacts:impacts_array
                    }
                    streamwork._create_risk_callback = controller.craete_risk_callback;
                    var jsonString = JSON.stringify(riskObjectRM);
                    $.ajax({
                        url:'http://' + controller.host + '/sap/resources/risks/_' + jsonString,
                        type:'GET',
                        dataType:'jsonp',
                        jsonp:'streamwork._create_risk_callback',
                        data:jsonString,
                        async:false,
                        success:function (data) {
                            risk_id = data;
                        },
                        error:function (data) {
                            //alert("error");
                        }
                    });


                }
                else {
                    var options = {
                        id:risk_id,
                        value:risk_for_db
                    };
                    impacts_array = [];
                    proxy.create_risk(options);
                }
            }, //create_risk
            //----------------------------------------------- UPDATE RISK ------------------------------------------------
            update_risk:function (risk) {
                view.loading_target = view.div;
                lipstick.addWaitOverlay(view.loading_target);
                //view.show_loading();
                var impacts_array = risk.impacts;
                if (controller.host == null) {
                    var impacts = {};
                    for (var i = 0; i < impacts_array.length; i++) {
                        impacts[i] = impacts_array[i];
                    }
                }
                else {
                    impacts = impacts_array;
                }

                var risk_for_db = {
                    name:risk.name,
                    category:risk.category,
                    category_id:risk.category_id,
                    description:risk.description,
                    org_unit:risk.org_unit,
                    org_unit_id:risk.org_unit_id,
                    impacts:impacts,
                    rm_assessment_id:risk.rm_assessment_id,
                    deleted:risk.deleted
                }
                //alert(risk.rm_assessment_id);
                var options = {
                    id:risk.id,
                    value:{
                        name:risk_for_db.name,
                        category:risk_for_db.category,
                        category_id:risk_for_db.category_id,
                        description:risk_for_db.description,
                        org_unit:risk_for_db.org_unit,
                        org_unit_id:risk_for_db.org_unit_id,
                        impacts:risk_for_db.impacts, //edited by D053422
                        rm_assessment_id:risk_for_db.rm_assessment_id,
                        deleted:risk_for_db.deleted
                    }
                }
                impacts_array = [];
                proxy.update_risk(options);
            }, //update_risk
            //----------------------------------------------- CREATE IMPACT LEVEL ------------------------------------------------
            create_impact_level:function (impact_level) {
                var options = {
                    value:impact_level.value,
                    text:impact_level.text,
                    id:impact_level.id
                }
                proxy.create_impact_level(options);
            }, //create_impact_level
            //----------------------------------------------- UPDATE IMPACT LEVEL ------------------------------------------------
            update_impact_level:function (impact_level) {
                var options = {
                    value:impact_level.value,
                    text:impact_level.text,
                    id:impact_level.id
                }
                proxy.update_impact_level(options);
            }, //update_impact_level
            //---------------------------------------------- CREATE PROBABILITY LEVEL --------------------------------------------
            create_probability_level:function (probability_level) {
                var options = {
                    value:probability_level.value,
                    text:probability_level.text,
                    id:probability_level.id
                }
                proxy.create_probability_level(options);
            }, //create_probability_level
            //----------------------------------------------- UPDATE PROBABILITY LEVEL ------------------------------------------------
            update_probability_level:function (probability_level) {
                var options = {
                    value:probability_level.value,
                    text:probability_level.text,
                    id:probability_level.id
                }
                proxy.update_probability_level(options);
            }, //update_probability_level
            //ADDITIONAL CODING BY D053422
            //---------------------------------------------- CREATE MITIGATION LEVEL --------------------------------------------
            create_mitigation_level:function (mitigation_level) {
                var options = {
                    value:mitigation_level.value,
                    text:mitigation_level.text,
                    id:mitigation_level.id
                }
                proxy.create_mitigation_level(options);
            }, //create_probability_level
            //----------------------------------------------- UPDATE MITIGATION LEVEL ------------------------------------------------
            update_mitigation_level:function (mitigation_level) {
                var options = {
                    value:mitigation_level.value,
                    text:mitigation_level.text,
                    id:mitigation_level.id
                }
                proxy.update_mitigation_level(options);
            }, //update_probability_level
            //---------------------------------------------- CREATE RESIDUAL LEVEL --------------------------------------------
            create_residual_level:function (residual_level) {
                var options = {
                    value:residual_level.value,
                    text:residual_level.text,
                    id:residual_level.id
                }
                proxy.create_residual_level(options);
            }, //create_probability_level
            //----------------------------------------------- UPDATE RESIDUAL LEVEL ------------------------------------------------
            update_residual_level:function (residual_level) {
                var options = {
                    value:residual_level.value,
                    text:residual_level.text,
                    id:residual_level.id
                }
                proxy.update_residual_level(options);
            }, //update_probability_level
            //ENF OF ADDITIONAL CODING
            //----------------------------------------------- CREATE RISK CATEGORY ------------------------------------------------
            create_risk_category:function () {
                //console.log("Create Risk Category...");
                var new_risk_div = $('#' + view.new_risk_div_id), category_name = $('#new_category_input', new_risk_div).val();
                //23.12.2011 from here if added
                if (category_name != '') {
                    var options = {
                        id:generate_id(),
                        value:{
                            category_name:category_name
                        }

                    };
                    proxy.create_risk_category(options);
                }
            }, //create_risk
            //----------------------------------------------- CREATE ORG UNIT ------------------------------------------------
            create_org_unit:function () {
                //console.log("Create Organisation Unit...");
                var new_risk_div = $('#' + view.new_risk_div_id), org_unit = $('#new_org_unit_input', new_risk_div).val();
                //23.12.2011 from here if added
                if (org_unit != '') {
                    var options = {
                        id:generate_id(),
                        value:{
                            org_unit:org_unit
                        }
                    };
                    proxy.create_org_unit(options);
                }
            }, //create_org_unit
            //----------------------------------------------- CREATE IMPACT CATEGORY ------------------------------------------------
            create_impact_category:function () {
                //console.log("Create Impact Category...");
                var new_risk_div = $('#' + view.new_risk_div_id), impact_category = $('#new_impact_category_input').val();
                //23.12.2011 from here if added
                if (impact_category != '') {
                    var options = {
                        id:generate_id(),
                        value:{
                            impact_category:impact_category
                        }

                    };
                    proxy.create_impact_category(options);
                }
            }, //create_impact_category
            //----------------------------------------------- SET HOST ------------------------------------------------
            set_host:function (host) {
                //alert("set host");
                controller.host = host;
                proxy.set_host(host);

            }, //set host

            update_first_load:function () {
                proxy.update_first_loaded(false);
            },

            //----------------------------------- CALLBACK: impact_name_missing --------------------------------------------
            impact_name_missing:function () {

            }, //impact_name_missing
            //----------------------------------- CALLBACK: DELETE IMPACT --------------------------------------------
            impact_deleted:function (data) {
                //alert("impact deleted");
            }, //impact_deleted
            //----------------------------------- CALLBACK: UPADTE IMPACT -------------------------------------------------
            impact_updated:function (data) {
                //alert("impact updated");
            }, //impact_updated
            //----------------------------------- CALLBACK: UPADTE PROBABILITY -------------------------------------------------
            probability_updated:function (data) {
                //alert("probability updated");
            }, //probability_updated
            //----------------------------------- CALLBACK: DELETE PROBABILITY --------------------------------------------
            probability_deleted:function (data) {
                //alert("probability deleted");
            }, //probability_deleted
            //----------------------------------- CALLBACK: DELETE MITIGATION _ ADDED BY D053422-------------------------------------
            mitigation_deleted:function (data) {
                //alert("mitigation deleted");
            }, //mitigation_deleted
            //----------------------------------- CALLBACK: UPDATE MITIGATION _ ADDED BY D053422---------------------------
            mitigation_updated:function (data) {
                //alert("mitigation updated");
            }, //mitigation_updated
            //----------------------------------- CALLBACK: DELETE RESIDUAL _ ADDED BY D053422-------------------------------------
            residual_deleted:function (data) {
                //alert("residual deleted");
            }, //residual_deleted
            //----------------------------------- CALLBACK: UPDATE RESIDUAL _ ADDED BY D053422---------------------------
            residual_updated:function (data) {
                //alert("residual updated");
            }, //residual
            //----------------------------------- CALLBACK: ASSESSMENT CONTAINER UPDATED --------------------------------------------
            assessment_container_updated:function (data) {
                //console.log("Assessment Container updated!");
                //alert("container updated");
            }, //assessment_container_updated
            //----------------------------------- CALLBACK: ASSESSMENT CONTAINER CREATED --------------------------------------------
            assessment_container_created:function (data) {
                //console.log("Assessment Container created!");
                //alert("container created");
            }, //assessment_container_created
            assessment_check:function () {

                f = false;

                for (var i = 0; i < controller.assessments.length; i++) {
                    if (controller.assessments[i].status != 'closed') {
                        f = true;
                        break;
                    }
                }

                if (f) {
                    jQuery('.create_assessment_link').parent().parent().hide();
                } else {
                    jQuery('.create_assessment_link').parent().parent().show();
                }

            },
            //---------------------------------------- CALLBACK: ASSESSMENT CREATED --------------------------------------------
            assessment_created:function (data) {
                //console.log("Assessment created!");
                //alert("assessment_created");
                var assessment = {
                    id:data.id,
                    name:data.value["name"],
                    deleted:data.value["deleted"],
                    status:data.value["status"],
                    start_date:data.value["start_date"],
                    due_date:data.value["due_date"],
                    risks:data.value["risks"],
                    results:data.value["results"],
                    owner:data.value["owner"],
                    assess_map:data.value["assess_map"],
                    edited_by:[]
                }

                controller.assessments.push(assessment);//c5139482
                controller.assessment_check();
            }, //asses   sment_created
            //---------------------------------------- CALLBACK: ASSESSMENT UPDATED --------------------------------------------
            assessment_updated:function (data) {

                //console.log("assessment updated");
                var assessment = {
                    id:data.id,
                    name:data.value["name"],
                    deleted:data.value["deleted"],
                    status:data.value["status"],
                    start_date:data.value["start_date"],
                    due_date:data.value["due_date"],
                    risks:data.value["risks"],
                    results:data.value["results"],
                    owner:data.value["owner"],
                    assess_map:data.value["assess_map"],
                    edited_by:data.value["edited_by"]
                }

                //only if the action wasn't delete
                if ((assessment.status == 'running' || assessment.status == 'closed') && assessment.deleted == false) {
                    var isNew = true;
                    for (var i = 0; i < controller.assessments.length; i++) {
                        if (assessment.id == controller.assessments[i].id) {
                            controller.assessments[i] = assessment;
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew) {
                        controller.assessments.push(assessment);
                    }

                    var show_assessments = true;

                    if (controller.host != null &&
                        assessment.edited_by == streamwork.getViewerId()) {
                        show_assessments = false;
                    }
                    /*
                     //skip if you are the last editor
                     if (assessment.edited_by == streamwork.getViewerId() &&
                     assessment.status != 'closed') {
                     return;
                     }

                     if (controller.host != null &&
                     assessment.edited_by == streamwork.getViewerId()){
                     return;
                     }
                     */
                    if (show_assessments) {
                        //update UI
                        $('#placeholder_create_new_assessment').empty();


                        for (var i = 0; i < controller.assessments.length; i++) {
                            var aAssessment = controller.assessments[i];

                            view.create_new_assessment(aAssessment.id, aAssessment);
                            //view.run_assessment(aAssessment.id, aAssessment);
                        }//for
                    }//if

                    view.div.data('init', true);
                }
                controller.assessment_check();
                lipstick.removeWaitOverlay(view.loading_target);
            }, //assessment_updated
            //---------------------------------------- CALLBACK: ASSESSMENT GOT FOR CLOSE ---------------------------------------------
            get_assessment_for_close_callback:function (data) {
                if (data.value != null) {
                    var assessment = data.value;
                    var index = data.id.indexOf("_");
                    index = data.id.indexOf("_", index + 1);
                    index = data.id.indexOf("_", index + 1);
                    index = data.id.indexOf("_", index + 1);
                    index = data.id.indexOf("_", index + 1);
                    var id = data.id.substring(index + 1);
                    assessment.id = id;
                    controller.aggregate_results(assessment);
                    assessment.status = "closed";
                    controller.update_assessment(assessment);
                    if (controller.host == null) {
                        view.show_assessment_results(id, assessment);
                    }
                }
                ;
            },
            //---------------------------------------- CALLBACK: AGGREGATION METHOD UPDATE --------------------------------------------
            aggregation_method_updated:function (data) {
                //alert("aggregation method updated");
            },

            //---------------------------------------- CALLBACK: SET CONFIG LOCK --------------------------------------------
            config_lock:function (data) {
                controller.config_locked = data.value;
                //alert("config lock toogled");
            },

            //---------------------------------------- CALLBACK: GET CONFIG LOCK --------------------------------------------
            get_config_lock:function (data) {
                controller.config_locked = data.value;
            },

            //-------------------------------------------------- ADD RISK ------------------------------------------------
            add_risk:function (data) {

            }, //add_risk
            //----------------------------------------------- CALLBACK: CREATE RISK ------------------------------------------------
            risk_created:function (data) {
                var risk = {
                    id:data.id,
                    name:data.value["name"],
                    description:data.value["description"],
                    category:data.value["category"],
                    category_id:data.value["category_id"],
                    org_unit:data.value["org_unit"],
                    org_unit_id:data.value["org_unit_id"],
                    deleted:data.value["deleted"],
                    rm_assessment_id:data.value["rm_assessment_id"],
                    impacts:data.value.impacts
                }
                controller.risks.push(risk);
                view.show_created_risk(risk);
                //view.show_created_risk(data.id, data.value["name"], data.value["description"], data.value["category"], data.value["org_unit"], data.value.impacts);
                view.div.data('init', true);
                //view.hide_loading();
                lipstick.removeWaitOverlay(view.loading_target);
                //console.log("Risk created!");
            }, //risk_created
            //----------------------------------------------- CALLBACK: UPDATE RISK ---------------------------------------------------
            risk_updated:function (data) {
                var updatedRisk = {
                    id:data.id,
                    name:data.value["name"],
                    description:data.value["description"],
                    category:data.value["category"],
                    category_id:data.value["category_id"],
                    org_unit:data.value["org_unit"],
                    org_unit_id:data.value["org_unit_id"],
                    deleted:data.value["deleted"],
                    rm_assessment_id:data.value["rm_assessment_id"],
                    impacts:data.value.impacts
                }
                //only if the action wasn't delete
                if (updatedRisk.deleted == false) {
                    //find updated risk is controller.risks
                    for (var i = 0; i < controller.risks.length; i++) {
                        if (updatedRisk.id == controller.risks[i].id) {
                            controller.risks[i] = updatedRisk;
                            break;
                        }
                    }

                    //update UI
                    $('#placeholder_new_risks').empty();

                    for (var i = 0; i < controller.risks.length; i++) {
                        var aRisk = controller.risks[i];

                        view.show_created_risk(aRisk);
                    }
                }

                lipstick.removeWaitOverlay(view.loading_target);
                //alert("risk updated; Risk: " + data.value.rm_assessment_id);
            }, //risk_updated
            //----------------------------------------------- CALLBACK: CREATE RISK CATEGORY ------------------------------------------------
            risk_category_created:function (data) {
                controller.selected_category_id = data.id;
                lipstick.removeWaitOverlay(view.loading_target); //changed by D053422
                proxy.get_risk_categories();
                //console.log("Risk Category created!");
            }, //risk_category_created
            //----------------------------------------------- CALLBACK: CREATE ORG UNIT ------------------------------------------------
            org_unit_created:function (data) {
                controller.selected_org_unit_id = data.id;
                lipstick.removeWaitOverlay(view.loading_target); //changed by D053422
                proxy.get_org_units();
                //console.log("Organisation Unit created!");
            }, //org_unit_created
            //----------------------------------------------- CALLBACK: PROBABILITY LEVEL CREATED ------------------------------------------
            probability_level_created:function (data) {
                lipstick.removeWaitOverlay(view.loading_targetd);
                //alert("probability level created");
            }, //probability_level_created
            //----------------------------------------------- CALLBACK: CREATE IMPACT LEVEL ------------------------------------------------
            impact_level_created:function (data) {
                lipstick.removeWaitOverlay(view.loading_targetd);
                //alert("impact level created");
            }, //impact_level_created
            //-------ADDED BY D053422------------------------ CALLBACK: MITIGATION EFFECTIVENESS LEVEL CREATED -----------------------------
            mitigation_level_created:function (data) {
                lipstick.removeWaitOverlay(view.loading_targetd);
                //alert("probability level created");
            }, //mitigation_level_created
            //-------ADDED BY D053422------------------------ CALLBACK: RESIDUAL RISK STATUS LEVEL CREATED -----------------------------
            residual_level_created:function (data) {
                lipstick.removeWaitOverlay(view.loading_targetd);
                //alert("probability level created");
            }, //residual_level_created
            //----------------------------------------------- CALLBACK: CREATE IMPACT CATEGORY ---------------------------------------------
            impact_category_created:function (data) {
                controller.selected_impact_category = data.id;
                proxy.get_impact_categories();
                //console.log("Impact Category created!");
            }, //impact_category_created
            save_data_container:function (data) {
                //alert("data conainer saved");
            }, //save_data_container
            data_updated:function (data) {
                //alert("data updated");
            }, //data_updated
            load_data_container:function (data) {
            }, //load_data_container
            //----------------------------------------------- CALLBACK: GET RISKS ------------------------------------------------
            get_risks_for_select:function (data) {
                var select_risk_div = $('#' + controller.select_risks_to_use);
                select_risk_div.empty();
                select_risk_div.append('<option value="0"></option> ');
                for (var i = 0; i < data.value.length; i++) {
                    var risk = data.value[i], name = risk.value["name"];
                    select_risk_div_string = '<option value="' + risk.id + '">' + name + '</option> ';
                    select_risk_div.append(select_risk_div_string);
                }//for
                //view.hide_loading();
                lipstick.removeWaitOverlay(loading_target);
            }, //get_data_response_for_select

            //----------------------------------------------- CALLBACK: GET HOST ------------------------------------------------
            host_got:function (data) {
                //alert('host: ' + data);
                controller.host = data;
            },
            //----------------------------------------------- CALLBACK: SET HOST ------------------------------------------------
            host_set:function (data) {
                //alert("host set");
                controller.update_first_load();
                //alert('host set to ' + data);
                if (data.value != null) {
                    controller.host = data.value;
                }
            },

            //----------------------------------------------- CALLBACK: UPDATE FIRST LOAD ----------------------------------------
            first_load_updated:function (data) {
                lipstick.removeWaitOverlay(view.loading_target);
                if (controller.host != null) {
                    controller.get_customizing();
                }

                //alert("first load updated");
            },

            //----------------------------------------------- CALLBACK: GET RISK CATEGORIES ------------------------------------------------
            get_risk_categories:function (data) {
                $('#div_new_category_input', new_risk_div).attr('style', 'display:none;');
                $('#div_select_category', new_risk_div).attr('style', 'display:block;');
                var new_risk_div = $('#' + view.new_risk_div_id), select_category = $('#select_category', new_risk_div);
                select_category.empty();
                select_category.append('<option value="0" id="empty_category"></option>');
                if (data.value) {
                    for (var i = 0; i < data.value.length; i++) {
                        var category = data.value[i], risk_category = category.value["category_name"];
                        select_category.append('<option id=' + category.id + ' value = ' + category.id + '>' + risk_category + '</option>');
                    }//for
                }
                select_category.append('<option id="newCategory" value="1">Create new Category</option>');
                select_category.attr('value', controller.selected_category_id);
                //$('#newCategory', new_risk_div).click(function(){
                $('#select_category', new_risk_div).change(function () {
                    //view.show_new_risk_category();
                    if ($('#select_category :selected', new_risk_div).val() == 1) {
                        $('#new_category_input', new_risk_div).addClass("default_text");
                        $('#new_category_input', new_risk_div).val("New Risk Category");
                        $('#div_new_category_input', new_risk_div).css('display', 'block');
                        //$('#new_category_input').focus();
                        $('#div_select_category', new_risk_div).css('display', 'none');
                    }
                });
                controller.selected_category_id = 0;
                //view.hide_loading();
                //lipstick.removeWaitOverlay(view.loading_target);
            }, //get_risk_categories
            //------------------ CALLBACK: GET RISK CATEGORIES FOR EDIT RIST (ADDED BY D053422)---------------------------------------
            /*get_risk_categories_for_edit: function(data) {
             $('#div_new_category_input', new_risk_div).attr('style', 'display:none;');
             $('#div_select_category', new_risk_div).attr('style', 'display:block;');
             var new_risk_div = $('#' + view.new_risk_div_id), select_category = $('#select_category', new_risk_div);
             select_category.empty();
             select_category.append('<option value="0" id="empty_category"></option>');
             if (data.value) {
             for (var i = 0; i < data.value.length; i++) {
             var category = data.value[i], risk_category = category.value["category_name"];
             select_category.append('<option id=' + category.id + ' value = ' + category.id + '>' + risk_category + '</option>');
             }//for
             }
             select_category.append('<option id="newCategory" value="1">Create new Category</option>');
             select_category.attr('value', controller.selected_category_id);
             //$('#newCategory', new_risk_div).click(function(){
             $('#select_category', new_risk_div).change(function() {
             //view.show_new_risk_category();
             if ($('#select_category :selected', new_risk_div).val() == 1) {
             $('#new_category_input', new_risk_div).addClass("default_text");
             $('#new_category_input', new_risk_div).val("New Risk Category");
             $('#div_new_category_input', new_risk_div).css('display', 'block');
             //$('#new_category_input').focus();
             $('#div_select_category', new_risk_div).css('display', 'none');
             }
             });
             controller.selected_category_id = 0;
             //view.hide_loading();
             //lipstick.removeWaitOverlay(view.loading_target);
             },//get_risk_categories   */
            //----------------------------------------------- CALLBACK: GET ORG UNITS ------------------------------------------------
            get_org_units:function (data) {
                $('#div_new_org_unit_input', new_risk_div).attr('style', 'display:none;');
                $('#div_select_org_unit', new_risk_div).attr('style', 'display:block;');
                var new_risk_div = $('#' + view.new_risk_div_id), select_org_unit = $('#select_org_unit', new_risk_div);
                select_org_unit.empty();
                select_org_unit.append('<option value="0" id="empty_org"></option>');
                if (data.value) {
                    for (var i = 0; i < data.value.length; i++) {
                        var org = data.value[i], org_unit = org.value["org_unit"];
                        select_org_unit.append('<option id=' + org.id + ' value = ' + org.id + '>' + org_unit + '</option>');
                    }//for
                }
                select_org_unit.append('<option id="newOrgUnit" value="1">Create new Organization Unit</option>');
                select_org_unit.attr('value', controller.selected_org_unit_id);
                $('#select_org_unit', new_risk_div).change(function () {
                    //$('#newOrgUnit').click(function(){
                    if ($('#select_org_unit :selected', new_risk_div).val() == 1) {
                        $('#new_org_unit_input', new_risk_div).addClass("default_text");
                        $('#new_org_unit_input', new_risk_div).val("New Organization Unit");
                        $('#div_new_org_unit_input', new_risk_div).css('display', 'block');
                        //$('#new_org_unit_input').focus();
                        $('#div_select_org_unit', new_risk_div).css('display', 'none');
                    }
                });
                controller.selected_org_unit_id = 0;
                //view.hide_loading();
                //lipstick.removeWaitOverlay(view.loading_target);
            }, //get_org_units
            //----------------------------------------------- CALLBACK: GET IMPACT CATEGORIES ------------------------------------------------
            get_impact_categories:function (data) {
                $('#div_new_impact_category_input', new_risk_div).attr('style', 'display:none;');
                $('#div_select_impact_category', new_risk_div).attr('style', 'display:block;');
                var new_risk_div = $('#' + view.new_risk_div_id), select_impact_category = $('#select_impact_category');
                select_impact_category.empty();
                select_impact_category.append('<option value="0" id="empty_org"></option>');
                if (data.value) {
                    for (var i = 0; i < data.value.length; i++) {
                        var category = data.value[i], impact_category = category.value["impact_category"];
                        select_impact_category.append('<option id=' + category.id + ' value = ' + category.id + '>' +
                            impact_category +
                            '</option>');
                    }//for
                }
                select_impact_category.append('<option id="newImpactCategory" value="1">Create new Impact Category</option>');
                select_impact_category.attr('value', controller.selected_impact_category);
                $('#select_impact_category').change(function () {
                    //$('#newImpactCategory').click(function(){
                    if ($('#select_impact_category').val() == 1) {
                        $('#new_impact_category_input').addClass("default_text");
                        $('#new_impact_category_input').val("New Impact Category");
                        $('#div_new_impact_category_input').css('display', 'block');
                        //$('#new_org_unit_input').focus();
                        $('#div_select_impact_category').css('display', 'none');
                    }
                });
                controller.selected_impact_category = 0;
                //view.hide_loading();

                if (controller.impact_table_input_ids) {
                    for (var i = 0; i < controller.impact_table_input_ids.length; i++) {
                        var select = $('#' + controller.impact_table_input_ids[i].category, new_risk_div);
                        for (var j = 0; j < data.value.length; j++) {
                            var category = data.value[j];
                            var impact_category = category.value["impact_category"];
                            if ($(':selected', select).text() != impact_category) {
                                select.append('<option id="' + category.id + '" value = "' + impact_category + '">' +
                                    impact_category +
                                    '</option>');
                            }
                        }
                    }
                }

                lipstick.removeWaitOverlay(view.loading_target);
            }, //get_impact_categories
            save_data_container:function (data) {
                //alert("The data has been updated: " + data.value);
            }, //save_data_container

            //ADDITIONAL CODING BY D053422
            risk_table_header_updated:function (data) {
                console.log('Risk Table Header Title saved!');
            }, //risk_table_header_updated

            risk_table_header_got:function (data) {
                //update the value on the UI
                if (data != null) {
                    var storedText = data.value;
                    if (storedText != null) {
                        $('#' + view.risk_header_title_id).val(storedText);
                    }//if inside
                }//if outside
            }//risk_table_header_got
            //END OF ADDITIONAL CODING
        };//controller
        return controller.init();
        //proxy.get_risks("get_data_response_for_select");
    };

    // copied from cstar_pbe_swot.js
    ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'.split('');
    function generate_id() {
        var chars = ID_CHARS;
        var rand = Math.random, flr = Math.floor;
        var id = [];
        var i;
        for (i = 0; i < 12; i++) {
            id[i] = chars[flr(rand() * 62)];
        }
        return id.join('');
    }

    function make_placeholder(input) {
        // initialize the data on the element
        input.addClass('rank_placeholder_text').one('focus', function (evt) {
            $(this).removeClass('rank_placeholder_text').val('');
        });
    }

    function pretty_alert(str, obj) {
        str = str || null;
        lipstick.alert(JSON.stringify(obj, null, '    '), null, str);
    }

    $.getJSONP = function (s) {
        s.dataType = 'jsonp';
        $.ajax(s);

        // figure out what the callback fn is
        var $script = $(document.getElementsByTagName('head')[0].firstChild);
        var url = $script.attr('src') || '';
        var cb = (url.match(/callback=(\w+)/) || [])[1];
        if (!cb)
            return; // bail
        var t = 0, cbFn = window[cb];

        $script[0].onerror = function (e) {
            $script.remove();
            handleError(s, {}, "error", e);
            clearTimeout(t);
        };

        if (!s.timeout)
            return;

        window[cb] = function (json) {
            clearTimeout(t);
            cbFn(json);
            cbFn = null;
        };

        t = setTimeout(function () {
            $script.remove();
            handleError(s, {}, "timeout");
            if (cbFn)
                window[cb] = function () {
                };
        }, s.timeout);

        function handleError(s, o, msg, e) {
            // support jquery versions before and after 1.4.3
            //($.ajax.handleError || $.handleError)(s, o, msg, e);
        }
    };

})();
